Skip to content
Merged
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
23 changes: 7 additions & 16 deletions components/ILIAS/LegalDocuments/classes/ValidHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ public function isTrue(string $string): bool
throw new ErrorException($message, $severity, $severity, $file, $line);
});

$dom = new DOMDocument();
$import_succeeded = $dom->loadHTML($string);
$dom = \Dom\HtmlDocument::createFromString($string, LIBXML_HTML_NOIMPLIED);

$errors = libxml_get_errors();
libxml_clear_errors();
libxml_use_internal_errors($error_state);

if (
!$import_succeeded ||
[] !== array_filter(
$errors,
static fn(LibXMLError $error): bool => $error->code !== self::UNKNOWN_TAG
Expand All @@ -65,22 +63,15 @@ public function isTrue(string $string): bool
return false;
}

$iter = new RecursiveIteratorIterator(
new ilHtmlDomNodeIterator($dom),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iter as $element) {
/** @var DOMNode $element */
if (strtolower($element->nodeName) === 'body') {
continue;
}

if ($element->nodeType === XML_ELEMENT_NODE) {
return true;
for ($nodes = [$dom]; $nodes !== []; array_shift($nodes)) {
$element = current($nodes);
if ($element->nodeType === XML_ELEMENT_NODE && !preg_match('/^[a-zA-Z0-9-]+$/', $element->nodeName)) {
Comment thread
mjansenDatabay marked this conversation as resolved.
Resolved
return false;
}
$nodes = array_merge($nodes, iterator_to_array($element->childNodes));
}

return false;
return true;
Comment thread
mjansenDatabay marked this conversation as resolved.
Resolved
} catch (Throwable) {
$errors = libxml_get_errors();
libxml_clear_errors();
Expand Down
Loading