From b423b9d230a5367679a9e4afca562e492f4bd796 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Mon, 27 May 2024 10:27:28 +0200 Subject: [PATCH] Fixes the problem when a link is inserted by the `HtmlInputNodeTextParser` and is located in a `` element, for example. This was recognized as an independent link in a line. --- .../node/HtmlInputNodeProcessor.class.php | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php index e10aa20cc2..bea017334f 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php @@ -798,40 +798,38 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor } } elseif ($parent->nodeName === 'p') { $parentLinkElement = $link; - while ($parentLinkElement->parentNode !== $parent) { + $nextSibling = $this->getNonEmptyNode($parentLinkElement, 'nextSibling'); + $previousSibling = $this->getNonEmptyNode($parentLinkElement, 'previousSibling'); + + while ( + $parentLinkElement->parentNode !== $parent && + $nextSibling === null && + $previousSibling === null + ) { $parentLinkElement = $parentLinkElement->parentNode; \assert($parentLinkElement instanceof \DOMElement); - if ($this->mayContainOtherContent($parentLinkElement, $linebreaks)) { - $mayContainOtherContent = true; - break; - } + $nextSibling = $this->getNonEmptyNode($parentLinkElement, 'nextSibling'); + $previousSibling = $this->getNonEmptyNode($parentLinkElement, 'previousSibling'); } - if (!$mayContainOtherContent) { - $nextSibling = $this->getNonEmptyNode($parentLinkElement, 'nextSibling') ?? - $this->getNonEmptyNode($link, 'nextSibling'); - $previousSibling = $this->getNonEmptyNode($parentLinkElement, 'previousSibling') ?? - $this->getNonEmptyNode($link, 'previousSibling'); - - // Check whether the link is the only content in the line. - // To do this, we need to check whether the next/previous sibling is a `
' element or - // is the start/end of the paragraph. - //

https://example.com
…

- //

…
https://example.com

- //

…
https://example.com
…

- //

…
https://example.com
…

- - if ($nextSibling !== null && $nextSibling->nodeName === 'br') { - $nextSibling = null; - } - if ($previousSibling !== null && $previousSibling->nodeName === 'br') { - $previousSibling = null; - } + // Check whether the link is the only content in the line. + // To do this, we need to check whether the next/previous sibling is a `
' element or + // is the start/end of the paragraph. + //

https://example.com
…

+ //

…
https://example.com

+ //

…
https://example.com
…

+ //

…
https://example.com
…

- if ($nextSibling === null && $previousSibling === null) { - $this->plainLinks[] = $plainLink->setIsStandalone($parent, false); - continue; - } + if ($nextSibling !== null && $nextSibling->nodeName === 'br') { + $nextSibling = null; + } + if ($previousSibling !== null && $previousSibling->nodeName === 'br') { + $previousSibling = null; + } + + if ($nextSibling === null && $previousSibling === null) { + $this->plainLinks[] = $plainLink->setIsStandalone($parent, false); + continue; } } -- 2.20.1