Optimize the performance when dealing with excessive node counts
authorAlexander Ebert <ebert@woltlab.com>
Mon, 30 Mar 2020 23:03:47 +0000 (01:03 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 30 Mar 2020 23:03:47 +0000 (01:03 +0200)
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php

index 2b923da1d4f18270be2792647bde9ce703d53ed5..bd9b35e9f49429851cff160bd58c4637036c58a6 100644 (file)
@@ -268,11 +268,10 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor {
                        $node = $node->nextSibling;
                }
                
-               // remove style attributes from non-whitelisted elements
-               $elements = $this->getDocument()->getElementsByTagName('*');
-               for ($i = 0, $length = $elements->length; $i < $length; $i++) {
-                       $element = $elements->item($i);
-                       if ($element->hasAttribute('style') && !in_array($element->nodeName, self::$allowedStyleElements)) {
+               // Remove style attributes from non-whitelisted elements.
+               /** @var \DOMElement $element */
+               foreach ($this->getXPath()->query('//*[@style]') as $element) {
+                       if (!in_array($element->nodeName, self::$allowedStyleElements)) {
                                $element->removeAttribute('style');
                        }
                }