diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index d24f938238..cdbc4aee09 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -333,7 +333,7 @@ function get_context(string $text, array $words, int $length = 400): string } // We need to turn the entities back into their original form, to not cut the message in between them - $text = html_entity_decode($text); + $text = htmlspecialchars_decode($text); // Replace all spaces/invisible characters with single spaces $text = preg_replace("/\s+/u", ' ', $text); @@ -414,7 +414,7 @@ function get_context(string $text, array $words, int $length = 400): string $output[] = utf8_substr($fragment, $fragment_start, $fragment_end - $fragment_start + 1); } - return ($fragments[0][0] !== 0 ? '... ' : '') . htmlentities(implode(' ... ', $output)) . ($end < $text_length - 1 ? ' ...' : ''); + return ($fragments[0][0] !== 0 ? '... ' : '') . htmlspecialchars(implode(' ... ', $output)) . ($end < $text_length - 1 ? ' ...' : ''); } /** diff --git a/tests/functions_content/get_context_test.php b/tests/functions_content/get_context_test.php index be8618dd8a..d4d087d675 100644 --- a/tests/functions_content/get_context_test.php +++ b/tests/functions_content/get_context_test.php @@ -112,6 +112,12 @@ class phpbb_functions_content_get_context_test extends TestCase 'words' => ['word1', 'word2'], 'length' => 10, 'expected' => 'word1 ... word2', + ], + 'fruits_spanish' => [ + 'text' => 'Manzana,plátano,naranja,fresa,mango,uva,piña,pera,kiwi,cereza,sandía,melón,papaya,arándano,durazno', + 'words' => ['piña'], + 'length' => 20, + 'expected' => '... uva,piña,pera, ...', ] ]; }