From c414a3cced9b39922d1087d84c20a3434d8d14c1 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 6 Aug 2021 16:44:42 +0200 Subject: [PATCH] Strip de fact empty paragraphs in messages --- .../node/HtmlInputNodeProcessor.class.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 14c910f22f..db60a8cbc5 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 @@ -103,6 +103,10 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor 'pre', 'sub', 'sup', + 'strong', + 'del', + 'em', + 'u', ]; /** @@ -490,6 +494,33 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor $quote->removeChild($removeElement); } } + + // Strip de facto empty text nodes that are the result from quirky formatting, for example: + //

+ /** @var \DOMElement $paragraph */ + foreach ($this->getXPath()->query('//p') as $paragraph) { + $textContent = StringUtil::trim($paragraph->textContent); + if ($textContent !== '') { + continue; + } + + /** @var \DOMElement $element */ + foreach ($paragraph->getElementsByTagName('*') as $element) { + if (!\in_array($element->nodeName, self::$emptyTags)) { + continue 2; + } + } + + // Do not strip content that contains non empty spans, such as icons. + /** @var \DOMElement $element */ + foreach ($paragraph->getElementsByTagName('span') as $element) { + if ($element->getAttribute('class')) { + continue 2; + } + } + + $paragraph->parentNode->removeChild($paragraph); + } } /** -- 2.20.1