From 5db42e11336a250908386c82308ca517f5a60dce Mon Sep 17 00:00:00 2001 From: Lukas Scharmer Date: Tue, 10 Nov 2026 13:43:45 +0100 Subject: [PATCH] LegalDocuments: Change unit test & ValidHTML check due to libxml version --- components/ILIAS/LegalDocuments/classes/ValidHTML.php | 10 +++++++--- .../ILIAS/LegalDocuments/tests/ValidHTMLTest.php | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/ILIAS/LegalDocuments/classes/ValidHTML.php b/components/ILIAS/LegalDocuments/classes/ValidHTML.php index edf106fe055a..ef431e064cf3 100755 --- a/components/ILIAS/LegalDocuments/classes/ValidHTML.php +++ b/components/ILIAS/LegalDocuments/classes/ValidHTML.php @@ -49,7 +49,7 @@ public function isTrue(string $string): bool }); $dom = new DOMDocument(); - $import_succeeded = $dom->loadHTML($string); + $import_succeeded = $dom->loadHTML($string, LIBXML_PEDANTIC); $errors = libxml_get_errors(); libxml_clear_errors(); @@ -69,6 +69,7 @@ public function isTrue(string $string): bool new ilHtmlDomNodeIterator($dom), RecursiveIteratorIterator::SELF_FIRST ); + $ret = false; foreach ($iter as $element) { /** @var DOMNode $element */ if (strtolower($element->nodeName) === 'body') { @@ -76,11 +77,14 @@ public function isTrue(string $string): bool } if ($element->nodeType === XML_ELEMENT_NODE) { - return true; + if (!preg_match('/^[a-zA-Z0-9-]+$/', $element->localName)) { + return false; + } + $ret = true; } } - return false; + return $ret; } catch (Throwable) { $errors = libxml_get_errors(); libxml_clear_errors(); diff --git a/components/ILIAS/LegalDocuments/tests/ValidHTMLTest.php b/components/ILIAS/LegalDocuments/tests/ValidHTMLTest.php index b832cd14f826..1d2843efbf32 100755 --- a/components/ILIAS/LegalDocuments/tests/ValidHTMLTest.php +++ b/components/ILIAS/LegalDocuments/tests/ValidHTMLTest.php @@ -47,7 +47,6 @@ public static function textProvider(): array 'HTML' => ['phpunit', true], 'HTML with Email Address Wrapped in <>' => ['phpunitPhp Unit ', false], 'HTML with Unsupported Entities' => ['phpunitPhp Unit
', true], - 'Invalid HTML' => ['phpunitPhp Unit
', false], ]; } }