From 5dbf319e06cb93dc40fd44635aea11a4b4d58296 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 6 Aug 2019 08:20:48 -0400 Subject: [PATCH 1/3] Fix bug removing spaces between hashtag links in HTML::toPlaintext --- src/Content/Text/HTML.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index c127973b13..89079fb38d 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 < count($node->childNodes) -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', [], "", ""); From d1db9bc8e621cc4a42e3a4003c19154d6962cac7 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 6 Aug 2019 08:21:26 -0400 Subject: [PATCH 2/3] Add test case for hashtag link list space removal --- tests/datasets/content/text/html/bug-7474.html | 1 + tests/datasets/content/text/html/bug-7474.txt | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/datasets/content/text/html/bug-7474.html create mode 100644 tests/datasets/content/text/html/bug-7474.txt 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 0000000000..0bba94e63a --- /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 0000000000..f590db5446 --- /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 From 79374dbf7a57ffd31819ab230da506117233520a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 6 Aug 2019 09:00:32 -0400 Subject: [PATCH 3/3] Fix DOMNodeList length compatibility with PHP <7.2 in Content\Text\HTML --- src/Content/Text/HTML.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index 89079fb38d..688895da92 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -102,7 +102,7 @@ class HTML /** @var \DOMNode $child */ 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 < count($node->childNodes) -1 || trim($child->nodeValue)) { + if ($key > 0 && $key < $node->childNodes->length - 1 || trim($child->nodeValue)) { $newNode = $child->cloneNode(true); $node->parentNode->insertBefore($newNode, $node); }