MDL-87482 core: Better text comparison

This commit is contained in:
Huong Nguyen
2026-02-13 09:32:00 +07:00
parent c32438bc79
commit 36493b1ac1
2 changed files with 10 additions and 4 deletions
+5 -2
View File
@@ -329,8 +329,11 @@ class formatting {
$domdoc->saveHTML($domdoc->documentElement),
));
// Libxml2 >= 2.14.0 doesn't wrap plain text in <p> tags, so add them for consistency.
if (LIBXML_VERSION >= 21400 && !empty($text) && !preg_match('/^\s*</', $text)) {
$text = '<p>' . $text . '</p>';
if (LIBXML_VERSION >= 21400) {
$trimmed = trim($text);
if ($trimmed !== '' && !preg_match('/^</', $trimmed)) {
$text = '<p>' . $text . '</p>';
}
}
// The meta charset approach preserves leading/trailing whitespace in <p> tags more than the old XML
// declaration approach. Normalize this by trimming whitespace inside <p> tags to match old behavior.
+5 -2
View File
@@ -720,8 +720,11 @@ class helper {
// Remove <body> element added in C14N function.
$html = preg_replace('~<(/?(?:body))[^>]*>\s*~i', '', $html);
// Libxml2 >= 2.14.0 doesn't wrap plain text in <p> tags, so add them for consistency.
if (LIBXML_VERSION >= 21400 && !empty($html) && !preg_match('/^\s*</', $html)) {
$html = '<p>' . $html . '</p>';
if (LIBXML_VERSION >= 21400) {
$trimmed = trim($html);
if ($trimmed !== '' && !preg_match('/^</', $trimmed)) {
$html = '<p>' . $html . '</p>';
}
}
}
}