From f141f5acf4548d23c6c6dd8d755d6d3f3b45e592 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 5 Dec 2020 19:55:01 -0500 Subject: [PATCH 1/2] Prevents share block new lines from being converted to HTML
tags - Address https://github.com/friendica/friendica/pull/9621#issuecomment-739333767 --- src/Content/Text/BBCode.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 38171d295..32eb35f76 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1378,6 +1378,9 @@ class BBCode } while ($oldtext != $text); } + // Add HTML new lines + $text = str_replace("\n", '
', $text); + /// @todo Have a closer look at the different html modes // Handle attached links or videos if ($simple_html == self::ACTIVITYPUB) { @@ -1848,18 +1851,16 @@ class BBCode return $text; }); // Escaped noparse, nobb, pre - // Remove escaping tags - $text = preg_replace("/\[noparse\](.*?)\[\/noparse\]/ism", '\1', $text); - $text = preg_replace("/\[nobb\](.*?)\[\/nobb\]/ism", '\1', $text); + // Remove escaping tags and replace new lines that remain + $text = preg_replace_callback("/\[(noparse|nobb)\](.*?)\[\/\1\]/ism", function ($match) { + return str_replace("\n", "
", $match[2]); + }, $text); // Additionally, [pre] tags preserve spaces $text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", function ($match) { - return str_replace(' ', ' ', htmlentities($match[1], ENT_NOQUOTES,'UTF-8')); + return str_replace([' ', "\n"], [' ', "
"], htmlentities($match[1], ENT_NOQUOTES,'UTF-8')); }, $text); - // Add HTML new lines - $text = str_replace("\n", '
', $text); - return $text; }); // Escaped code From e6270bc46d4f3cf3722b9c0ec644aafbff44f975 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 6 Dec 2020 08:57:06 -0500 Subject: [PATCH 2/2] Enable back references in reg exp in BBCode::convert - Bump BBCode version --- src/Content/Text/BBCode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 32eb35f76..73503cece 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -50,7 +50,7 @@ use Friendica\Util\XML; class BBCode { // Update this value to the current date whenever changes are made to BBCode::convert - const VERSION = '2020-12-03'; + const VERSION = '2020-12-06'; const INTERNAL = 0; const API = 2; @@ -1852,7 +1852,7 @@ class BBCode }); // Escaped noparse, nobb, pre // Remove escaping tags and replace new lines that remain - $text = preg_replace_callback("/\[(noparse|nobb)\](.*?)\[\/\1\]/ism", function ($match) { + $text = preg_replace_callback('/\[(noparse|nobb)](.*?)\[\/\1]/ism', function ($match) { return str_replace("\n", "
", $match[2]); }, $text);