From 66b6a5e1f396c5f6150fe8301ae8afaeb0255720 Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 2 Sep 2024 17:46:16 +0700 Subject: [PATCH] [ticket/17387] Make regex match unicode characters PHPBB-17387 --- phpBB/includes/functions_content.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index a2038d12a6..d24f938238 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -400,13 +400,13 @@ function get_context(string $text, array $words, int $length = 400): string $fragment_end = $end - $start + 1; // Find the first valid alphanumeric character in the fragment to don't cut words - if ($start > 0 && preg_match('/[^a-zA-Z0-9][a-zA-Z0-9]/u', $fragment, $matches, PREG_OFFSET_CAPTURE)) + if ($start > 0 && preg_match('/[^\p{L}\p{N}][\p{L}\p{N}]/ui', $fragment, $matches, PREG_OFFSET_CAPTURE)) { $fragment_start = (int) $matches[0][1] + 1; // first valid alphanumeric character } // Find the last valid alphanumeric character in the fragment to don't cut words - if ($end < $text_length - 1 && preg_match_all('/[a-zA-Z0-9][^a-zA-Z0-9]/u', $fragment, $matches, PREG_OFFSET_CAPTURE)) + if ($end < $text_length - 1 && preg_match_all('/[\p{L}\p{N}][^\p{L}\p{N}]/ui', $fragment, $matches, PREG_OFFSET_CAPTURE)) { $fragment_end = end($matches[0])[1]; // last valid alphanumeric character }