Fix mail integration fails for mails with having not encoded ampersands on their html content

This commit is contained in:
Hadi Nategh 2021-04-27 17:41:34 +02:00
parent f5e2f7e719
commit 59dbd27719

View File

@ -491,13 +491,14 @@ class Html
{ {
return $html; return $html;
} }
// try to cleanup not encoded ampersands used possibily in urls
$html = preg_replace('/&(?!#?[a-zA-Z0-9]+;)/', '&', $html);
$dom = new \DOMDocument('1.0','UTF-8'); $dom = new \DOMDocument('1.0','UTF-8');
$dom->loadHTML( if(!$dom->loadHTML(
'<?xml encoding="UTF-8">'. Api\Translation::convert($html,false, 'utf8'), '<?xml encoding="UTF-8">'. Api\Translation::convert($html,preg_match('/<meta[^>]+content="[^>"]+charset=([^;"]+)/i', $html, $matches) ? $matches[1] : false, 'utf8'),
LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS
); ))
if(!$dom)
{ {
// Failed to parse // Failed to parse
return $html; return $html;