From: Cyperghost Date: Thu, 11 Apr 2024 10:48:47 +0000 (+0200) Subject: Insert raw bb-code text for non-closing bb-code X-Git-Tag: 6.1.0_Alpha_1~129^2~6 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9519d6a9fc9709af04837d8f32dd5fee70187e6f;p=GitHub%2FWoltLab%2FWCF.git Insert raw bb-code text for non-closing bb-code --- 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); + } }