Filter out nested links before attempting to process them
authorAlexander Ebert <ebert@woltlab.com>
Thu, 4 Jan 2024 13:15:52 +0000 (14:15 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 4 Jan 2024 13:15:52 +0000 (14:15 +0100)
See https://www.woltlab.com/community/thread/303962/

wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php

index 97212a649ad45bac32486f78ea7a59b7e0839a34..3234761de4acfcbb3278228113ba6d4e5f23a29c 100644 (file)
@@ -33,6 +33,26 @@ class HtmlOutputNodeA extends AbstractHtmlOutputNode
      */
     public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor)
     {
+        // Find links that are nested inside other links.
+        $nestedLinks = \array_filter(
+            $elements,
+            static fn (\DOMElement $element) => DOMUtil::hasParent($element, 'a'),
+        );
+
+        if ($nestedLinks !== []) {
+            $elements = \array_filter(
+                $elements,
+                static function (\DOMElement $element) use ($nestedLinks) {
+                    if (\in_array($element, $nestedLinks, true)) {
+                        DOMUtil::removeNode($element, true);
+                        return false;
+                    }
+
+                    return true;
+                }
+            );
+        }
+
         /** @var \DOMElement $element */
         foreach ($elements as $element) {
             try {