From 8a8893fbd364def7757c5c3c7dedddbef7275c91 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Fri, 6 Nov 2020 23:07:30 +0100 Subject: [PATCH] [ticket/16630] Restore clean_formatting()'s behaviour PHPBB3-16630 --- phpBB/includes/functions_content.php | 2 +- phpBB/phpbb/textformatter/s9e/utils.php | 5 ++++- phpBB/phpbb/textformatter/utils_interface.php | 6 +++++- tests/text_formatter/s9e/utils_test.php | 8 ++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index bfd6b179cd..6980328db6 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -532,7 +532,7 @@ function strip_bbcode(&$text, $uid = '') if (preg_match('#^<[rt][ >]#', $text)) { - $text = $phpbb_container->get('text_formatter.utils')->clean_formatting($text); + $text = utf8_htmlspecialchars($phpbb_container->get('text_formatter.utils')->clean_formatting($text)); } else { diff --git a/phpBB/phpbb/textformatter/s9e/utils.php b/phpBB/phpbb/textformatter/s9e/utils.php index d81424e913..1c77d89976 100644 --- a/phpBB/phpbb/textformatter/s9e/utils.php +++ b/phpBB/phpbb/textformatter/s9e/utils.php @@ -15,6 +15,9 @@ namespace phpbb\textformatter\s9e; /** * Text manipulation utilities +* +* In this implementation, "plain text" refers to regular text as it would be inputted by a user. +* "Parsed text" is XML suitable to be reinserted into the database. */ class utils implements \phpbb\textformatter\utils_interface { @@ -31,7 +34,7 @@ class utils implements \phpbb\textformatter\utils_interface // Insert a space before and then remove formatting $xml = preg_replace('#<[es]>#', ' $0', $xml); - return utf8_htmlspecialchars(\s9e\TextFormatter\Utils::removeFormatting($xml)); + return \s9e\TextFormatter\Utils::removeFormatting($xml); } /** diff --git a/phpBB/phpbb/textformatter/utils_interface.php b/phpBB/phpbb/textformatter/utils_interface.php index 4b7392976a..c8e842d7cb 100644 --- a/phpBB/phpbb/textformatter/utils_interface.php +++ b/phpBB/phpbb/textformatter/utils_interface.php @@ -15,6 +15,10 @@ namespace phpbb\textformatter; /** * Used to manipulate a parsed text +* +* In this interface, "plain text" refers to regular text as it would be inputted by a user. +* "Parsed text" refers to whichever form is returned by the implementation after parsing, which +* should be suitable to be reinserted into the database. */ interface utils_interface { @@ -73,7 +77,7 @@ interface utils_interface * Return whether or not a parsed text represent an empty text. * * @param string $text Parsed text - * @return bool Tue if the original text is empty + * @return bool True if the original text is empty */ public function is_empty($text); } diff --git a/tests/text_formatter/s9e/utils_test.php b/tests/text_formatter/s9e/utils_test.php index 719d3cda88..2754574c27 100644 --- a/tests/text_formatter/s9e/utils_test.php +++ b/tests/text_formatter/s9e/utils_test.php @@ -60,13 +60,17 @@ class phpbb_textformatter_s9e_utils_test extends phpbb_test_case 'Plain text', 'Plain text' ), + array( + 'Plain & boring', + 'Plain & boring' + ), array( "Multi
\nline
", "Multi\nline" ), array( - '[b]bold[/b]', - ' bold ' + '[b]bold[/b] & [i]italic[/i]', + ' bold & italic ' ) ); }