diff options
author | Michał Węgrzynek <michal.wegrzynek@malloc.com.pl> | 2019-12-09 17:22:49 +0100 |
---|---|---|
committer | Backportbot <backportbot-noreply@rullzer.com> | 2019-12-13 14:39:17 +0000 |
commit | 3031a36f4b59bc5a4c84e608f37c5835667f1282 (patch) | |
tree | 2c522e30a0ff5279346738780ce3fd2cd4c8d218 /apps | |
parent | 458f4398eff93f2bb29bb2c1d03160e8c8b04f88 (diff) | |
download | nextcloud-server-3031a36f4b59bc5a4c84e608f37c5835667f1282.tar.gz nextcloud-server-3031a36f4b59bc5a4c84e608f37c5835667f1282.zip |
Fix comments search result to work with multibyte strings
Currently, the searching in comments breaks up, if comments contain multibyte characters and string manipulation logic in getRelevantMessagePart happens to cut through them rendering the resulting string invalid (not UTF-8 compliant). This patch replaces all string manipulating functions in this code to multibyte aware ones.
Signed-off-by: Michał Węgrzynek <michal.wegrzynek@malloc.com.pl>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/comments/lib/Search/Result.php | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/apps/comments/lib/Search/Result.php b/apps/comments/lib/Search/Result.php index 0a48f9d7b5a..cbce0250b67 100644 --- a/apps/comments/lib/Search/Result.php +++ b/apps/comments/lib/Search/Result.php @@ -80,12 +80,12 @@ class Result extends BaseResult { * @throws NotFoundException */ protected function getRelevantMessagePart(string $message, string $search): string { - $start = stripos($message, $search); + $start = mb_stripos($message, $search); if ($start === false) { throw new NotFoundException('Comment section not found'); } - $end = $start + strlen($search); + $end = $start + mb_strlen($search); if ($start <= 25) { $start = 0; @@ -95,15 +95,15 @@ class Result extends BaseResult { $prefix = '…'; } - if ((strlen($message) - $end) <= 25) { - $end = strlen($message); + if ((mb_strlen($message) - $end) <= 25) { + $end = mb_strlen($message); $suffix = ''; } else { $end += 25; $suffix = '…'; } - return $prefix . substr($message, $start, $end - $start) . $suffix; + return $prefix . mb_substr($message, $start, $end - $start) . $suffix; } } |