From 3e1b6890b7584ccc542f43b389ee4d5fe24bfe00 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 24 Sep 2022 21:53:50 -0400 Subject: [PATCH] Fix removing falsy text nodes in HTML::tagToBBCodeSub - This wrongly removed text nodes containing just '0' --- src/Content/Text/HTML.php | 6 +++--- tests/src/Content/Text/HTMLTest.php | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index 9121087296..93afeac4d0 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -114,7 +114,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 < $node->childNodes->length - 1 || $child->nodeName != '#text' || trim($child->nodeValue)) { + if ($key > 0 && $key < $node->childNodes->length - 1 || $child->nodeName != '#text' || trim($child->nodeValue) !== '') { $newNode = $child->cloneNode(true); $node->parentNode->insertBefore($newNode, $node); } @@ -144,10 +144,10 @@ class HTML public static function toBBCode(string $message, string $basepath = ''): string { /* - * Check if message is empty to prevent a lot code below being executed + * Check if message is empty to prevent a lot of code below from being executed * for just an empty message. */ - if (empty($message)) { + if ($message === '') { return ''; } diff --git a/tests/src/Content/Text/HTMLTest.php b/tests/src/Content/Text/HTMLTest.php index 3fcdf064c4..bc352e5427 100644 --- a/tests/src/Content/Text/HTMLTest.php +++ b/tests/src/Content/Text/HTMLTest.php @@ -82,6 +82,10 @@ its surprisingly good", 'html' => "

Now playing

echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6));}" | gcc -o a.out -x c - 2> /dev/null
 ./a.out | aplay -q 2> /dev/null

its surprisingly good

", ], + 'bug-11851-content-0' => [ + 'expectedBBCode' => '[url=https://dev-friendica.mrpetovan.com/profile/hypolite]@hypolite[/url] 0', + 'html' => '

@hypolite 0

', + ], ]; }