]> git.mxchange.org Git - friendica.git/commitdiff
Fix removing falsy text nodes in HTML::tagToBBCodeSub
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 25 Sep 2022 01:53:50 +0000 (21:53 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 25 Sep 2022 02:03:49 +0000 (22:03 -0400)
- This wrongly removed text nodes containing just '0'

src/Content/Text/HTML.php
tests/src/Content/Text/HTMLTest.php

index 9121087296a977d539e89018546af79c822615d0..93afeac4d056b9d0db38d7218f4d0973b51df846 100644 (file)
@@ -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 '';
                }
 
index 3fcdf064c4a505a32dd44b6438a6281a64329886..bc352e542788c3469cf44b209771f8a43612e411 100644 (file)
@@ -82,6 +82,10 @@ its surprisingly good",
                                'html' => "<p>Now playing</p><pre><code>echo &quot;main(i){for(i=0;;i++)putchar(((i*(i&gt;&gt;8|i&gt;&gt;9)&amp;46&amp;i&gt;&gt;8))^(i&amp;i&gt;&gt;13|i&gt;&gt;6));}&quot; | gcc -o a.out -x c - 2&gt; /dev/null
 ./a.out | aplay -q 2&gt; /dev/null</code></pre><p>its surprisingly good</p>",
                        ],
+                       'bug-11851-content-0' => [
+                               'expectedBBCode' => '[url=https://dev-friendica.mrpetovan.com/profile/hypolite]@hypolite[/url] 0',
+                               'html' => '<p><span class="h-card"><a href="https://dev-friendica.mrpetovan.com/profile/hypolite" class="u-url mention">@<span>hypolite</span></a></span> 0</p>',
+                       ],
                ];
        }