From 8acba2db024aa2a2c96037db65fbaab8f82aa1c8 Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 1 Sep 2024 22:31:22 +0700 Subject: [PATCH] [ticket/17387] Return entire post text for zero or negative length value In according to 'Default number of returned characters' setting ACP explanation `A value of 0 will return the entire post`. Do the same for negative values too PHPBB-17387 --- phpBB/includes/functions_content.php | 4 ++-- tests/functions_content/get_context_test.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 3dded3c6e9..a2038d12a6 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -329,10 +329,10 @@ function get_context(string $text, array $words, int $length = 400): string { if ($length <= 0) { - return '...'; + return $text; } - // we need to turn the entities back into their original form, to not cut the message in between them + // We need to turn the entities back into their original form, to not cut the message in between them $text = html_entity_decode($text); // Replace all spaces/invisible characters with single spaces diff --git a/tests/functions_content/get_context_test.php b/tests/functions_content/get_context_test.php index 59f6cdf846..be8618dd8a 100644 --- a/tests/functions_content/get_context_test.php +++ b/tests/functions_content/get_context_test.php @@ -81,13 +81,13 @@ class phpbb_functions_content_get_context_test extends TestCase 'text' => 'This is a sample text.', 'words' => ['sample'], 'length' => 0, - 'expected' => '...', + 'expected' => 'This is a sample text.', ], 'negative length' => [ 'text' => 'This is a sample text.', 'words' => ['sample'], 'length' => -10, - 'expected' => '...', + 'expected' => 'This is a sample text.', ], 'ellipses_beginning' => [ 'text' => 'foo foo foo foo foo foo foo foo bar',