Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions components/ILIAS/LegalDocuments/classes/ValidHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -69,18 +69,22 @@ 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') {
continue;
}

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();
Expand Down
1 change: 0 additions & 1 deletion components/ILIAS/LegalDocuments/tests/ValidHTMLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static function textProvider(): array
'HTML' => ['<html><body>php<b>unit</b></body></html>', true],
'HTML with Email Address Wrapped in <>' => ['<html><body>php<b>unit</b>Php Unit <info@ilias.de></body></html>', false],
'HTML with Unsupported Entities' => ['<html><body>php<b>unit</b>Php Unit<figure></figure></body></html>', true],
'Invalid HTML' => ['<html><body>php<b>unit</b>Php Unit<div </body></html>', false],
];
}
}
Loading