From 0dac738e65fc903d8bf58290cf24ee04c14a15fd Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 29 Jan 2017 14:17:59 +0100 Subject: [PATCH] Fix AbstractHtmlInputNodeProcessorListener::replaceLinksWithBBCode() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … if multiple links are replaced --- ...actHtmlInputNodeProcessorListener.class.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/lib/system/event/listener/AbstractHtmlInputNodeProcessorListener.class.php b/wcfsetup/install/files/lib/system/event/listener/AbstractHtmlInputNodeProcessorListener.class.php index 9f0cec5e3a..ad93c7f1cb 100644 --- a/wcfsetup/install/files/lib/system/event/listener/AbstractHtmlInputNodeProcessorListener.class.php +++ b/wcfsetup/install/files/lib/system/event/listener/AbstractHtmlInputNodeProcessorListener.class.php @@ -61,6 +61,7 @@ abstract class AbstractHtmlInputNodeProcessorListener implements IParameterizedE * @param string $bbcodeName */ protected function replaceLinksWithBBCode(HtmlInputNodeProcessor $processor, Regex $regex, array $objects, $bbcodeName) { + $elements = []; foreach ($processor->getDocument()->getElementsByTagName('a') as $element) { /** @var \DOMElement $element */ if ($element->getAttribute('href') === $element->textContent) { @@ -68,15 +69,22 @@ abstract class AbstractHtmlInputNodeProcessorListener implements IParameterizedE $objectID = $regex->getMatches()[2][0]; if (isset($objects[$objectID])) { - $metacodeElement = $processor->getDocument()->createElement('woltlab-metacode'); - $metacodeElement->setAttribute('data-name', $bbcodeName); - $metacodeElement->setAttribute('data-attributes', base64_encode(JSON::encode([$objectID]))); - - DOMUtil::replaceElement($element, $metacodeElement, false); + $elements[] = [ + 'element' => $element, + 'objectID' => $objectID + ]; } } } } + + foreach ($elements as $elementData) { + $metacodeElement = $processor->getDocument()->createElement('woltlab-metacode'); + $metacodeElement->setAttribute('data-name', $bbcodeName); + $metacodeElement->setAttribute('data-attributes', base64_encode(JSON::encode([$elementData['objectID']]))); + + DOMUtil::replaceElement($elementData['element'], $metacodeElement, false); + } } /** -- 2.20.1