From: Matthias Schmidt Date: Sun, 29 Jan 2017 13:17:59 +0000 (+0100) Subject: Fix AbstractHtmlInputNodeProcessorListener::replaceLinksWithBBCode() X-Git-Tag: 3.0.2~44 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0dac738e65fc903d8bf58290cf24ee04c14a15fd;p=GitHub%2FWoltLab%2FWCF.git Fix AbstractHtmlInputNodeProcessorListener::replaceLinksWithBBCode() … if multiple links are replaced --- 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); + } } /**