From e571bbd05af9b034cc95615156200b0fa2cdeda0 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Thu, 11 Apr 2024 16:04:50 +0200 Subject: [PATCH] Remove the text nodes from the dom after set it as attribute --- .../files/lib/system/bbcode/DomBBCodeParser.class.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php index 0a27575f9f..4f90e9fbcd 100644 --- a/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php @@ -70,7 +70,9 @@ final class DomBBCodeParser extends SingletonFactory } } - // get text between opening and closing tags + // Get the text between the opening and closing tags + // and remove it from the DOM. + $nodes = []; foreach ($this->useTextNodes as ['uuid' => $uuid, 'metacodeMarker' => $node, 'attributeNo' => $attributeNo]) { $nextNode = $node->nextSibling; while ($nextNode !== null) { @@ -102,6 +104,8 @@ final class DomBBCodeParser extends SingletonFactory $text = ''; $currentNode = $node->nextSibling; while ($currentNode !== $nextNode) { + $nodes[] = $currentNode; + $text .= $currentNode->textContent; $currentNode = $currentNode->nextSibling; } @@ -114,6 +118,9 @@ final class DomBBCodeParser extends SingletonFactory $attributes[$attributeNo] = $text; $node->setAttribute('data-attributes', \base64_encode(JSON::encode($attributes))); } + foreach ($nodes as $node) { + $node->parentNode->removeChild($node); + } } private function convertBBCodeToMetacodeMarker(\DOMNode $node): void -- 2.20.1