From 3c0d6339bb12bd7fbf65ba7a79078e39737b4387 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 24 Mar 2024 17:50:27 +0100 Subject: make sure we preserve linefeeds in the actual content of lists and tables also add tests --- include/bbcode.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index aa1257a56..1ced24ec3 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1060,8 +1060,8 @@ function bb_fix_lf($match) { // be converted to '
' and turn your neatly crafted tables into a whole lot of // empty space. - $new_content = str_replace(["\n\r", "\n", "\r"], '', $match[1]); - return str_replace($match[1], $new_content, $match[0]); + $new_content = preg_replace("/\]\s+\[/",'][', $match[1]); + return str_replace($match[1], trim($new_content, "\r\n"), $match[0]); } function bbtopoll($s) { @@ -1554,6 +1554,20 @@ function bbcode($text, $options = []) { $text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism", 'bb_checklist', $text); } + + if (strpos($text,'[/table]') !== false) { + $text = str_replace(["[/table]\r", "[/table]\n"], '[/table]', $text); + + $text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fix_lf',$text); + $text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '$1
', $text); + + $text = preg_replace_callback("/\[table border=1\](.*?)\[\/table\]/ism",'bb_fix_lf',$text); + $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
', $text); + + $text = preg_replace_callback("/\[table border=0\](.*?)\[\/table\]/ism",'bb_fix_lf',$text); + $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
', $text); + } + if (strpos($text,'[th]') !== false) { $text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1', $text); } @@ -1566,13 +1580,6 @@ function bbcode($text, $options = []) { $text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1', $text); } - if (strpos($text,'[/table]') !== false) { - $text = preg_replace_callback("/\[table\](.*?)\[\/table\]/ism",'bb_fix_lf',$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 = str_replace('[hr]', '
', $text); // This is actually executed in prepare_body() -- cgit v1.2.3