From 1146fca2cd43f79b42ee8434932b8df35cfd1ae4 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 06:10:56 +0000 Subject: [PATCH 01/10] HTML: Use paragraphs instead of double line breaks --- src/Content/Text/BBCode.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 33f91b43d..c9bbc02c9 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1460,6 +1460,7 @@ class BBCode // @deprecated since 2021.12, left for backward-compatibility reasons $text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism", '$2', $text); // Add HTML new lines + $text = str_replace("\n\n", '

', $text); $text = str_replace("\n", '
', $text); // handle nested lists @@ -1938,7 +1939,7 @@ class BBCode : [] ); - $text = HTML::purify($text, $allowedIframeDomains); + $text = HTML::purify('

' . $text . '

', $allowedIframeDomains); DI::profiler()->stopRecording(); return trim($text); From eee65b31fd67067d13a2cff068b8c38fba145066 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 06:55:38 +0000 Subject: [PATCH 02/10] Fix tests --- tests/src/Content/Text/BBCodeTest.php | 4 ++-- tests/src/Factory/Api/Twitter/DirectMessageTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 4c1292344..073a441f0 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -146,7 +146,7 @@ class BBCodeTest extends FixtureTest public function testAutoLinking(string $data, bool $assertHTML) { $output = BBCode::convert($data); - $assert = $this->HTMLPurifier->purify('' . $data . ''); + $assert = $this->HTMLPurifier->purify('

' . $data . '

'); if ($assertHTML) { self::assertEquals($assert, $output); } else { @@ -278,7 +278,7 @@ Karl Marx - Die ursprüngliche Akkumulation { $actual = BBCode::convert($text, $try_oembed, $simpleHtml, $forPlaintext); - self::assertEquals($expectedHtml, $actual); + self::assertEquals('

' . $expectedHtml . '

', $actual); } public function dataBBCodesToMarkdown() diff --git a/tests/src/Factory/Api/Twitter/DirectMessageTest.php b/tests/src/Factory/Api/Twitter/DirectMessageTest.php index 216c4051f..62a9c43e5 100644 --- a/tests/src/Factory/Api/Twitter/DirectMessageTest.php +++ b/tests/src/Factory/Api/Twitter/DirectMessageTest.php @@ -67,7 +67,7 @@ class DirectMessageTest extends FixtureTest ->toArray(); self::assertEquals('item_title', $directMessage['title']); - self::assertEquals('item_body', $directMessage['text']); + self::assertEquals('

item_body

', $directMessage['text']); } /** From 2a0ad0c4821846be89dabad29186affc074c92d0 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 06:58:21 +0000 Subject: [PATCH 03/10] Some more test fixed --- tests/src/Module/Api/Friendica/NotificationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Module/Api/Friendica/NotificationTest.php b/tests/src/Module/Api/Friendica/NotificationTest.php index aaf702202..e9eafc933 100644 --- a/tests/src/Module/Api/Friendica/NotificationTest.php +++ b/tests/src/Module/Api/Friendica/NotificationTest.php @@ -62,7 +62,7 @@ class NotificationTest extends ApiTest $assertXml = << - + XML; From 1a15951cae0e6ceda1a30a0a37ba75605c852b91 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 07:04:53 +0000 Subject: [PATCH 04/10] Tests --- tests/src/Content/Text/BBCodeTest.php | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 073a441f0..10be79c72 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -178,74 +178,74 @@ class BBCodeTest extends FixtureTest [/ul]', ], 'bug-2199-named-size' => [ - 'expectedHtml' => 'Test text', + 'expectedHtml' => '

Test text

', 'text' => '[size=xx-large]Test text[/size]', ], 'bug-2199-numeric-size' => [ - 'expectedHtml' => 'Test text', + 'expectedHtml' => '

Test text

', 'text' => '[size=24]Test text[/size]', ], 'bug-2199-diaspora-no-named-size' => [ - 'expectedHtml' => 'Test text', + 'expectedHtml' => '

Test text

', 'text' => '[size=xx-large]Test text[/size]', 'try_oembed' => false, // Triggers the diaspora compatible output 'simpleHtml' => BBCode::DIASPORA, ], 'bug-2199-diaspora-no-numeric-size' => [ - 'expectedHtml' => 'Test text', + 'expectedHtml' => '

Test text

', 'text' => '[size=24]Test text[/size]', 'try_oembed' => false, // Triggers the diaspora compatible output 'simpleHtml' => BBCode::DIASPORA, ], 'bug-7665-audio-tag' => [ - 'expectedHtml' => '', + 'expectedHtml' => '

', 'text' => '[audio]http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3[/audio]', 'try_oembed' => true, ], 'bug-7808-code-lt' => [ - 'expectedHtml' => '<', + 'expectedHtml' => '

<

', 'text' => '[code]<[/code]', ], 'bug-7808-code-gt' => [ - 'expectedHtml' => '>', + 'expectedHtml' => '

>

', 'text' => '[code]>[/code]', ], 'bug-7808-code-amp' => [ - 'expectedHtml' => '&', + 'expectedHtml' => '

&

', 'text' => '[code]&[/code]', ], 'task-8800-pre-spaces-notag' => [ - 'expectedHtml' => '[test] Space', + 'expectedHtml' => '

[test] Space

', 'text' => '[test] Space', ], 'task-8800-pre-spaces' => [ - 'expectedHtml' => '    Spaces', + 'expectedHtml' => '

    Spaces

', 'text' => '[pre] Spaces[/pre]', ], 'bug-9611-purify-xss-nobb' => [ - 'expectedHTML' => 'dare to move your mouse here', + 'expectedHTML' => '

dare to move your mouse here

', 'text' => '[nobb]dare to move your mouse here[/nobb]' ], 'bug-9611-purify-xss-noparse' => [ - 'expectedHTML' => 'dare to move your mouse here', + 'expectedHTML' => '

dare to move your mouse here

', 'text' => '[noparse]dare to move your mouse here[/noparse]' ], 'bug-9611-purify-xss-attributes' => [ - 'expectedHTML' => 'dare to move your mouse here', + 'expectedHTML' => '

dare to move your mouse here

', 'text' => '[color="onmouseover=alert(0) style="]dare to move your mouse here[/color]' ], 'bug-9611-purify-attributes-correct' => [ - 'expectedHTML' => 'dare to move your mouse here', + 'expectedHTML' => '

dare to move your mouse here

', 'text' => '[color=FFFFFF]dare to move your mouse here[/color]' ], 'bug-9639-span-classes' => [ - 'expectedHTML' => 'Test', + 'expectedHTML' => '

Test

', 'text' => '[class=arbitrary classes]Test[/class]', ], 'bug-10772-duplicated-links' => [ - 'expectedHTML' => 'Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen.
Karl Marx - Die ursprüngliche Akkumulation
https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation
#Podcast #Kapitalismus', + 'expectedHTML' => '

Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen.
Karl Marx - Die ursprüngliche Akkumulation
https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation
#Podcast #Kapitalismus

', 'text' => "Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen. Karl Marx - Die ursprüngliche Akkumulation [url=https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation]https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation[/url] @@ -255,7 +255,7 @@ Karl Marx - Die ursprüngliche Akkumulation 'simpleHtml' => BBCode::TWITTER, ], 'task-10886-deprecate-class' => [ - 'expectedHTML' => ':heart_nb:', + 'expectedHTML' => '

:heart_nb:

', 'text' => '[emoji=https://fedi.underscore.world/emoji/custom/custom/heart_nb.png]:heart_nb:[/emoji]', ] ]; @@ -278,7 +278,7 @@ Karl Marx - Die ursprüngliche Akkumulation { $actual = BBCode::convert($text, $try_oembed, $simpleHtml, $forPlaintext); - self::assertEquals('

' . $expectedHtml . '

', $actual); + self::assertEquals($expectedHtml, $actual); } public function dataBBCodesToMarkdown() From dfaf3eee6bb6ec33eb58be5eeb4fea16acc955a5 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 12:33:13 +0000 Subject: [PATCH 05/10] Only add paragraphs if needed --- src/Content/Text/BBCode.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index c9bbc02c9..609e4ef52 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -36,14 +36,10 @@ use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Event; -use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; -use Friendica\Object\Image; -use Friendica\Protocol\Activity; -use Friendica\Util\Images; use Friendica\Util\Map; use Friendica\Util\ParseUrl; use Friendica\Util\Proxy; @@ -1939,7 +1935,11 @@ class BBCode : [] ); - $text = HTML::purify('

' . $text . '

', $allowedIframeDomains); + if (strpos($text, '

') !== false || strpos($text, '

') !== false) { + $text = '

' . $text . '

'; + } + + $text = HTML::purify($text, $allowedIframeDomains); DI::profiler()->stopRecording(); return trim($text); From d4aec5cbd3701cee0650b00d9ab1f761114944f2 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 12:41:26 +0000 Subject: [PATCH 06/10] Revert tests --- tests/src/Content/Text/BBCodeTest.php | 36 +++++++++---------- .../Factory/Api/Twitter/DirectMessageTest.php | 2 +- .../Module/Api/Friendica/NotificationTest.php | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 10be79c72..16cbec330 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -146,7 +146,7 @@ class BBCodeTest extends FixtureTest public function testAutoLinking(string $data, bool $assertHTML) { $output = BBCode::convert($data); - $assert = $this->HTMLPurifier->purify('

' . $data . '

'); + $assert = $this->HTMLPurifier->purify('' . $data . ''); if ($assertHTML) { self::assertEquals($assert, $output); } else { @@ -178,74 +178,74 @@ class BBCodeTest extends FixtureTest [/ul]', ], 'bug-2199-named-size' => [ - 'expectedHtml' => '

Test text

', + 'expectedHtml' => 'Test text', 'text' => '[size=xx-large]Test text[/size]', ], 'bug-2199-numeric-size' => [ - 'expectedHtml' => '

Test text

', + 'expectedHtml' => 'Test text', 'text' => '[size=24]Test text[/size]', ], 'bug-2199-diaspora-no-named-size' => [ - 'expectedHtml' => '

Test text

', + 'expectedHtml' => 'Test text', 'text' => '[size=xx-large]Test text[/size]', 'try_oembed' => false, // Triggers the diaspora compatible output 'simpleHtml' => BBCode::DIASPORA, ], 'bug-2199-diaspora-no-numeric-size' => [ - 'expectedHtml' => '

Test text

', + 'expectedHtml' => 'Test text', 'text' => '[size=24]Test text[/size]', 'try_oembed' => false, // Triggers the diaspora compatible output 'simpleHtml' => BBCode::DIASPORA, ], 'bug-7665-audio-tag' => [ - 'expectedHtml' => '

', + 'expectedHtml' => '', 'text' => '[audio]http://www.cendrones.fr/colloque2017/jonathanbocquet.mp3[/audio]', 'try_oembed' => true, ], 'bug-7808-code-lt' => [ - 'expectedHtml' => '

<

', + 'expectedHtml' => '<', 'text' => '[code]<[/code]', ], 'bug-7808-code-gt' => [ - 'expectedHtml' => '

>

', + 'expectedHtml' => '>', 'text' => '[code]>[/code]', ], 'bug-7808-code-amp' => [ - 'expectedHtml' => '

&

', + 'expectedHtml' => '&', 'text' => '[code]&[/code]', ], 'task-8800-pre-spaces-notag' => [ - 'expectedHtml' => '

[test] Space

', + 'expectedHtml' => '[test] Space', 'text' => '[test] Space', ], 'task-8800-pre-spaces' => [ - 'expectedHtml' => '

    Spaces

', + 'expectedHtml' => ' Spaces', 'text' => '[pre] Spaces[/pre]', ], 'bug-9611-purify-xss-nobb' => [ - 'expectedHTML' => '

dare to move your mouse here

', + 'expectedHTML' => 'dare to move your mouse here', 'text' => '[nobb]dare to move your mouse here[/nobb]' ], 'bug-9611-purify-xss-noparse' => [ - 'expectedHTML' => '

dare to move your mouse here

', + 'expectedHTML' => 'dare to move your mouse here', 'text' => '[noparse]dare to move your mouse here[/noparse]' ], 'bug-9611-purify-xss-attributes' => [ - 'expectedHTML' => '

dare to move your mouse here

', + 'expectedHTML' => 'dare to move your mouse here', 'text' => '[color="onmouseover=alert(0) style="]dare to move your mouse here[/color]' ], 'bug-9611-purify-attributes-correct' => [ - 'expectedHTML' => '

dare to move your mouse here

', + 'expectedHTML' => 'dare to move your mouse here', 'text' => '[color=FFFFFF]dare to move your mouse here[/color]' ], 'bug-9639-span-classes' => [ - 'expectedHTML' => '

Test

', + 'expectedHTML' => 'Test', 'text' => '[class=arbitrary classes]Test[/class]', ], 'bug-10772-duplicated-links' => [ - 'expectedHTML' => '

Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen.
Karl Marx - Die ursprüngliche Akkumulation
https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation
#Podcast #Kapitalismus

', + 'expectedHTML' => 'Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen.
Karl Marx - Die ursprüngliche Akkumulation
https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation
#Podcast #Kapitalismus', 'text' => "Jetzt wird mir klar, warum Kapitalisten jedes Mal durchdrehen wenn Marx und das Kapital ins Gespräch kommt. Soziopathen. Karl Marx - Die ursprüngliche Akkumulation [url=https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation]https://wohlstandfueralle.podigee.io/107-urspruengliche-akkumulation[/url] @@ -255,7 +255,7 @@ Karl Marx - Die ursprüngliche Akkumulation 'simpleHtml' => BBCode::TWITTER, ], 'task-10886-deprecate-class' => [ - 'expectedHTML' => '

:heart_nb:

', + 'expectedHTML' => ':heart_nb:', 'text' => '[emoji=https://fedi.underscore.world/emoji/custom/custom/heart_nb.png]:heart_nb:[/emoji]', ] ]; diff --git a/tests/src/Factory/Api/Twitter/DirectMessageTest.php b/tests/src/Factory/Api/Twitter/DirectMessageTest.php index 62a9c43e5..216c4051f 100644 --- a/tests/src/Factory/Api/Twitter/DirectMessageTest.php +++ b/tests/src/Factory/Api/Twitter/DirectMessageTest.php @@ -67,7 +67,7 @@ class DirectMessageTest extends FixtureTest ->toArray(); self::assertEquals('item_title', $directMessage['title']); - self::assertEquals('

item_body

', $directMessage['text']); + self::assertEquals('item_body', $directMessage['text']); } /** diff --git a/tests/src/Module/Api/Friendica/NotificationTest.php b/tests/src/Module/Api/Friendica/NotificationTest.php index e9eafc933..aaf702202 100644 --- a/tests/src/Module/Api/Friendica/NotificationTest.php +++ b/tests/src/Module/Api/Friendica/NotificationTest.php @@ -62,7 +62,7 @@ class NotificationTest extends ApiTest $assertXml = << - + XML; From 84ec9b0814fa7281c379899d41243870bebe4d50 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 12:43:23 +0000 Subject: [PATCH 07/10] Restore tests --- tests/src/Content/Text/BBCodeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 16cbec330..4c1292344 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -221,7 +221,7 @@ class BBCodeTest extends FixtureTest 'text' => '[test] Space', ], 'task-8800-pre-spaces' => [ - 'expectedHtml' => ' Spaces', + 'expectedHtml' => '    Spaces', 'text' => '[pre] Spaces[/pre]', ], 'bug-9611-purify-xss-nobb' => [ From d058275723c4ac40f48f033d9308c9556c8fcef8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 17:40:22 +0000 Subject: [PATCH 08/10] Some tests added / ensure to have paragraphs --- src/Content/Text/BBCode.php | 40 +++++++++++++-------------- tests/src/Content/Text/BBCodeTest.php | 8 ++++++ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 609e4ef52..2e133372d 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1398,12 +1398,12 @@ class BBCode } // Check for headers - $text = preg_replace("(\[h1\](.*?)\[\/h1\])ism", '

$1

', $text); - $text = preg_replace("(\[h2\](.*?)\[\/h2\])ism", '

$1

', $text); - $text = preg_replace("(\[h3\](.*?)\[\/h3\])ism", '

$1

', $text); - $text = preg_replace("(\[h4\](.*?)\[\/h4\])ism", '

$1

', $text); - $text = preg_replace("(\[h5\](.*?)\[\/h5\])ism", '
$1
', $text); - $text = preg_replace("(\[h6\](.*?)\[\/h6\])ism", '
$1
', $text); + $text = preg_replace("(\[h1\](.*?)\[\/h1\])ism", '

$1

', $text); + $text = preg_replace("(\[h2\](.*?)\[\/h2\])ism", '

$1

', $text); + $text = preg_replace("(\[h3\](.*?)\[\/h3\])ism", '

$1

', $text); + $text = preg_replace("(\[h4\](.*?)\[\/h4\])ism", '

$1

', $text); + $text = preg_replace("(\[h5\](.*?)\[\/h5\])ism", '

$1

', $text); + $text = preg_replace("(\[h6\](.*?)\[\/h6\])ism", '

$1

', $text); // Check for paragraph $text = preg_replace("(\[p\](.*?)\[\/p\])ism", '

$1

', $text); @@ -1466,27 +1466,27 @@ class BBCode ((strpos($text, "[/ol]") !== false) && (strpos($text, "[ol]") !== false)) || ((strpos($text, "[/ul]") !== false) && (strpos($text, "[ul]") !== false)) || ((strpos($text, "[/li]") !== false) && (strpos($text, "[li]") !== false))) && (++$endlessloop < 20)) { - $text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '
    $1
', $text); - $text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '
    $1
', $text); - $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '
    $1
', $text); - $text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism", '
    $2
', $text); - $text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '
    $2
', $text); - $text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '
    $2
', $text); - $text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '
    $2
', $text); - $text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '
    $1
', $text); - $text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '
    $1
', $text); + $text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '

    $1

', $text); + $text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '

    $1

', $text); + $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '

    $1

', $text); + $text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism", '

    $2

', $text); + $text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '

    $2

', $text); + $text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '

    $2

', $text); + $text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '

    $2

', $text); + $text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '

    $1

', $text); + $text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '

    $1

', $text); $text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '

  • $1
  • ', $text); } $text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1', $text); $text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1', $text); $text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1', $text); - $text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '$1
    ', $text); + $text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '

    $1

    ', $text); - $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
    ', $text); - $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
    ', $text); + $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '

    $1

    ', $text); + $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '

    $1

    ', $text); - $text = str_replace('[hr]', '


    ', $text); + $text = str_replace('[hr]', '


    ', $text); if (!$for_plaintext) { $text = self::performWithEscapedTags($text, ['url', 'img', 'audio', 'video', 'youtube', 'vimeo', 'share', 'attachment', 'iframe', 'bookmark'], function ($text) { @@ -1520,7 +1520,7 @@ class BBCode } // Declare the format for [quote] layout - $QuoteLayout = '

    $1
    '; + $QuoteLayout = '

    $1

    '; // Check for [quote] text // handle nested quotes diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 4c1292344..82fdcc3cb 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -257,6 +257,14 @@ Karl Marx - Die ursprüngliche Akkumulation 'task-10886-deprecate-class' => [ 'expectedHTML' => ':heart_nb:', 'text' => '[emoji=https://fedi.underscore.world/emoji/custom/custom/heart_nb.png]:heart_nb:[/emoji]', + ], + 'task-12900-multiple-paragraphs' => [ + 'expectedHTML' => '

    Header

    • One
    • Two

    This is a paragraph
    with a line feed.

    Second Chapter

    ', + 'text' => '[h1]Header[/h1][ul][*]One[*]Two[/ul]\n\nThis is a paragraph\nwith a line feed.\n\nSecond Chapter', + ], + 'task-12900-header-with-paragraphs' => [ + 'expectedHTML' => '

    Header

    Some Chapter

    ', + 'text' => '[h1]Header[/h1]Some Chapter', ] ]; } From e55f38cc981ce1f8b80e9f9d9a61487f5395b5c3 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 18:01:51 +0000 Subject: [PATCH 09/10] Fix test --- src/Factory/Api/Twitter/Status.php | 2 +- tests/src/Content/Text/BBCodeTest.php | 2 +- tests/src/Factory/Api/Twitter/StatusTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Factory/Api/Twitter/Status.php b/src/Factory/Api/Twitter/Status.php index 810b421ca..b4b4039f6 100644 --- a/src/Factory/Api/Twitter/Status.php +++ b/src/Factory/Api/Twitter/Status.php @@ -141,7 +141,7 @@ class Status extends BaseFactory // Add the title to text / html if set if (!empty($item['title'])) { $text .= $item['title'] . ' '; - $title = sprintf("[h4]%s[/h4]\n", $item['title']); + $title = sprintf("[h4]%s[/h4]", $item['title']); } $statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($title . ($item['raw-body'] ?? $item['body'])), BBCode::TWITTER_API); diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 82fdcc3cb..b289414cc 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -259,7 +259,7 @@ Karl Marx - Die ursprüngliche Akkumulation 'text' => '[emoji=https://fedi.underscore.world/emoji/custom/custom/heart_nb.png]:heart_nb:[/emoji]', ], 'task-12900-multiple-paragraphs' => [ - 'expectedHTML' => '

    Header

    • One
    • Two

    This is a paragraph
    with a line feed.

    Second Chapter

    ', + 'expectedHTML' => "

    Header

    • One
    • Two

    This is a paragraph
    with a line feed.

    Second Chapter

    ", 'text' => '[h1]Header[/h1][ul][*]One[*]Two[/ul]\n\nThis is a paragraph\nwith a line feed.\n\nSecond Chapter', ], 'task-12900-header-with-paragraphs' => [ diff --git a/tests/src/Factory/Api/Twitter/StatusTest.php b/tests/src/Factory/Api/Twitter/StatusTest.php index 883894589..86b91deb3 100644 --- a/tests/src/Factory/Api/Twitter/StatusTest.php +++ b/tests/src/Factory/Api/Twitter/StatusTest.php @@ -64,7 +64,7 @@ class StatusTest extends FixtureTest ->toArray(); self::assertStringStartsWith('item_title', $status['text']); - self::assertStringStartsWith('

    item_title


    perspiciatis impedit voluptatem', $status['friendica_html']); + self::assertStringStartsWith('

    item_title

    perspiciatis impedit voluptatem', $status['friendica_html']); } /** From 92a04baf62bcd5b4621408efcee06d893edba448 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2023 18:08:37 +0000 Subject: [PATCH 10/10] Tests should now work --- tests/src/Content/Text/BBCodeTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index b289414cc..a7de2388e 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -259,8 +259,8 @@ Karl Marx - Die ursprüngliche Akkumulation 'text' => '[emoji=https://fedi.underscore.world/emoji/custom/custom/heart_nb.png]:heart_nb:[/emoji]', ], 'task-12900-multiple-paragraphs' => [ - 'expectedHTML' => "

    Header

    • One
    • Two

    This is a paragraph
    with a line feed.

    Second Chapter

    ", - 'text' => '[h1]Header[/h1][ul][*]One[*]Two[/ul]\n\nThis is a paragraph\nwith a line feed.\n\nSecond Chapter', + 'expectedHTML' => '

    Header

    • One
    • Two

    This is a paragraph
    with a line feed.

    Second Chapter

    ', + 'text' => "[h1]Header[/h1][ul][*]One[*]Two[/ul]\n\nThis is a paragraph\nwith a line feed.\n\nSecond Chapter", ], 'task-12900-header-with-paragraphs' => [ 'expectedHTML' => '

    Header

    Some Chapter

    ',