From 9519d6a9fc9709af04837d8f32dd5fee70187e6f Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Thu, 11 Apr 2024 12:48:47 +0200 Subject: [PATCH] Insert raw bb-code text for non-closing bb-code --- .../system/bbcode/DomBBCodeParser.class.php | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php b/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php index e0595aec75..cda0011320 100644 --- a/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/DomBBCodeParser.class.php @@ -21,7 +21,7 @@ use wcf\util\StringUtil; final class DomBBCodeParser extends SingletonFactory { /** - * @var string[][] + * @var array{uuid: string, metacodeMarker: \DOMElement}[] */ private array $openTagIdentifiers = []; /** @@ -52,9 +52,18 @@ final class DomBBCodeParser extends SingletonFactory $node->removeAttribute('data-name'); if (!isset($this->openTagIdentifiers[$name]) || empty($this->openTagIdentifiers[$name])) { + $this->insertBBCode($node); continue; } - $node->setAttribute('data-uuid', \array_pop($this->openTagIdentifiers[$name])); + ['uuid' => $uuid] = \array_pop($this->openTagIdentifiers[$name]); + $node->setAttribute('data-uuid', $uuid); + } + + // Insert raw BB-code text for each opening tag without a corresponding closing tag. + foreach ($this->openTagIdentifiers as $entries) { + foreach ($entries as ['metacodeMarker' => $node]) { + $this->insertBBCode($node); + } } // get text between opening and closing tags @@ -186,13 +195,16 @@ final class DomBBCodeParser extends SingletonFactory $this->openTagIdentifiers[$name] = []; } $uuid = StringUtil::getUUID(); - $this->openTagIdentifiers[$name][] = $uuid; + $this->openTagIdentifiers[$name][] = [ + 'uuid' => $uuid, + 'metacodeMarker' => $metacodeMarker + ]; $metacodeMarker->setAttribute('data-uuid', $uuid); foreach ($bbcode->getAttributes() as $attribute) { if ($attribute->useText && !isset($attributes[$attribute->attributeNo])) { - $metacodeMarker->setAttribute('data-use-text', 'true'); + $metacodeMarker->setAttribute('data-use-text', $attribute->attributeNo); $this->useTextNodes[] = [ 'uuid' => $uuid, 'metacodeMarker' => $metacodeMarker, @@ -327,4 +339,13 @@ final class DomBBCodeParser extends SingletonFactory return true; } + + private function insertBBCode(\DOMElement $node): void + { + DOMUtil::insertBefore( + $this->document->createTextNode(\base64_decode($node->getAttribute('data-source'))), + $node + ); + $node->parentNode->removeChild($node); + } } -- 2.20.1