From d3b75e0a5e245f583324536615a36b42831b169e Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Tue, 27 Apr 2021 17:41:34 +0200 Subject: [PATCH] Fix mail integration fails for mails with having not encoded ampersands on their html content --- api/src/Mail/Html.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/api/src/Mail/Html.php b/api/src/Mail/Html.php index 63efa8db7d..b97d380e07 100644 --- a/api/src/Mail/Html.php +++ b/api/src/Mail/Html.php @@ -491,13 +491,14 @@ class 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->loadHTML( - ''. Api\Translation::convert($html,false, 'utf8'), - LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS - ); - if(!$dom) + if(!$dom->loadHTML( + ''. Api\Translation::convert($html,preg_match('/]+content="[^>"]+charset=([^;"]+)/i', $html, $matches) ? $matches[1] : false, 'utf8'), + LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS + )) { // Failed to parse return $html;