diff --git a/public/lib/classes/formatting.php b/public/lib/classes/formatting.php index 497ae67a1cc..a84af402661 100644 --- a/public/lib/classes/formatting.php +++ b/public/lib/classes/formatting.php @@ -329,8 +329,11 @@ class formatting { $domdoc->saveHTML($domdoc->documentElement), )); // Libxml2 >= 2.14.0 doesn't wrap plain text in

tags, so add them for consistency. - if (LIBXML_VERSION >= 21400 && !empty($text) && !preg_match('/^\s*' . $text . '

'; + if (LIBXML_VERSION >= 21400) { + $trimmed = trim($text); + if ($trimmed !== '' && !preg_match('/^' . $text . '

'; + } } // The meta charset approach preserves leading/trailing whitespace in

tags more than the old XML // declaration approach. Normalize this by trimming whitespace inside

tags to match old behavior. diff --git a/public/message/classes/helper.php b/public/message/classes/helper.php index 7eab5188c44..4086a35f767 100644 --- a/public/message/classes/helper.php +++ b/public/message/classes/helper.php @@ -720,8 +720,11 @@ class helper { // Remove element added in C14N function. $html = preg_replace('~<(/?(?:body))[^>]*>\s*~i', '', $html); // Libxml2 >= 2.14.0 doesn't wrap plain text in

tags, so add them for consistency. - if (LIBXML_VERSION >= 21400 && !empty($html) && !preg_match('/^\s*' . $html . '

'; + if (LIBXML_VERSION >= 21400) { + $trimmed = trim($html); + if ($trimmed !== '' && !preg_match('/^' . $html . '

'; + } } } }