MDL-71919 core_message: Fix unclosed html tags in email notification
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
a2bd7e21df
commit
045fe3f45f
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
namespace core_message;
|
||||
use DOMDocument;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -677,4 +678,30 @@ class helper {
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent unclosed HTML elements in a message.
|
||||
*
|
||||
* @param string $message The html message.
|
||||
* @param bool $removebody True if we want to remove tag body.
|
||||
* @return string The html properly structured.
|
||||
*/
|
||||
public static function prevent_unclosed_html_tags(
|
||||
string $message,
|
||||
bool $removebody = false
|
||||
) : string
|
||||
{
|
||||
$html = '';
|
||||
if (!empty($message)) {
|
||||
$doc = new DOMDocument();
|
||||
@$doc->loadHTML($message);
|
||||
$html = $doc->getElementsByTagName('body')->item(0)->C14N(false, true);
|
||||
if ($removebody) {
|
||||
// Remove <body> element added in C14N function.
|
||||
$html = preg_replace('~<(/?(?:body))[^>]*>\s*~i', '', $html);
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user