diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index c127973b1..688895da9 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -100,8 +100,9 @@ class HTML if ($node->hasChildNodes()) { /** @var \DOMNode $child */ - foreach ($node->childNodes as $child) { - if (trim($child->nodeValue)) { + foreach ($node->childNodes as $key => $child) { + /* Remove empty text nodes at the start or at the end of the children list */ + if ($key > 0 && $key < $node->childNodes->length - 1 || trim($child->nodeValue)) { $newNode = $child->cloneNode(true); $node->parentNode->insertBefore($newNode, $node); } @@ -170,7 +171,7 @@ class HTML $message = mb_convert_encoding($message, 'HTML-ENTITIES', "UTF-8"); - @$doc->loadHTML($message); + @$doc->loadHTML($message, LIBXML_HTML_NODEFDTD); XML::deleteNode($doc, 'style'); XML::deleteNode($doc, 'head'); @@ -190,7 +191,8 @@ class HTML $message = $doc->saveHTML(); $message = str_replace(["\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"], ["<", ">", "
", " ", ""], $message); $message = preg_replace('= [\s]*=i', " ", $message); - @$doc->loadHTML($message); + + @$doc->loadHTML($message, LIBXML_HTML_NODEFDTD); self::tagToBBCode($doc, 'html', [], "", ""); self::tagToBBCode($doc, 'body', [], "", ""); diff --git a/tests/datasets/content/text/html/bug-7474.html b/tests/datasets/content/text/html/bug-7474.html new file mode 100644 index 000000000..0bba94e63 --- /dev/null +++ b/tests/datasets/content/text/html/bug-7474.html @@ -0,0 +1 @@ +

I recently released a PHP package that makes executing commands over SSH super simple. You can also upload/download files via SCP.

github.com/DivineOmega/php-ssh

\ No newline at end of file diff --git a/tests/datasets/content/text/html/bug-7474.txt b/tests/datasets/content/text/html/bug-7474.txt new file mode 100644 index 000000000..f590db544 --- /dev/null +++ b/tests/datasets/content/text/html/bug-7474.txt @@ -0,0 +1,11 @@ +I recently released a PHP package that makes executing commands over SSH super simple. You can also upload/download files via SCP. + +https://github.com/DivineOmega/php-ssh-connection + +#php #opensource #webdev #ssh #DevOps + +https://mastodon.xyz/tags/php +https://mastodon.xyz/tags/opensource +https://mastodon.xyz/tags/webdev +https://mastodon.xyz/tags/ssh +https://mastodon.xyz/tags/devops \ No newline at end of file