From: Alexander Ebert Date: Fri, 6 Aug 2021 14:44:42 +0000 (+0200) Subject: Strip de fact empty paragraphs in messages X-Git-Tag: 5.5.0_Alpha_1~502 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c414a3cced9b39922d1087d84c20a3434d8d14c1;p=GitHub%2FWoltLab%2FWCF.git Strip de fact empty paragraphs in messages --- 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); + } } /**