|
|
@@ -721,16 +721,18 @@ class Sanitize implements RegistryAware
|
|
|
&& !isset($this->allowed_html_elements_with_attributes[$tag])) {
|
|
|
if (!in_array($tag, ['script', 'style', 'svg', 'math', 'template'], true)) {
|
|
|
// Preserve children inside the disallowed element
|
|
|
- for ($i = $element->childNodes->length - 1; $i >= 0; $i--) {
|
|
|
- $child = $element->childNodes->item($i);
|
|
|
- if ($child === null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $nextSibling = $element->nextSibling;
|
|
|
+ while ($element->firstChild !== null) {
|
|
|
+ $child = $element->firstChild;
|
|
|
if ($child instanceof \DOMText) {
|
|
|
$child->nodeValue = htmlspecialchars($child->nodeValue ?? '', ENT_QUOTES, 'UTF-8');
|
|
|
}
|
|
|
if ($parent !== null) {
|
|
|
- $parent->insertBefore($child, $element);
|
|
|
+ if ($nextSibling !== null) {
|
|
|
+ $parent->insertBefore($child, $nextSibling);
|
|
|
+ } else {
|
|
|
+ $parent->appendChild($child);
|
|
|
+ }
|
|
|
}
|
|
|
$this->enforce_allowed_html_nodes($child, $allow_data_attr, $allow_aria_attr);
|
|
|
}
|