From 251a3791ddd26f619f014f1a012c05f513c70df5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 23 Jun 2020 07:52:38 -0400 Subject: [PATCH] Keep spaces after non-tags in Content\BBCode::convert - Added test case --- src/Content/Text/BBCode.php | 6 +++--- tests/src/Content/Text/BBCodeTest.php | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 1cd8e438cd..95484de720 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1299,9 +1299,9 @@ class BBCode // Remove the abstract element. It is a non visible element. $text = self::stripAbstract($text); - // Move all spaces out of the tags - $text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $text); - $text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $text); + // Move new lines outside of tags + $text = preg_replace("#\[(\w*)](\n*)#ism", '$2[$1]', $text); + $text = preg_replace("#(\n*)\[/(\w*)]#ism", '[/$2]$1', $text); // Extract the private images which use data urls since preg has issues with // large data sizes. Stash them away while we do bbcode conversion, and then put them back diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 35dff87d9f..82e2853e71 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -236,7 +236,11 @@ class BBCodeTest extends MockedTest 'bug-7808-code-amp' => [ 'expectedHtml' => '&', 'text' => '[code]&[/code]', - ] + ], + 'task-8800-pre-spaces-notag' => [ + 'expectedHtml' => '[test] Space', + 'text' => '[test] Space', + ], ]; }