Merge pull request #18302 from mwegrzynek/patch-1
Fix comments search result to work with multibyte strings
This commit is contained in:
commit
9cafc508d5
|
@ -82,12 +82,12 @@ class Result extends BaseResult {
|
||||||
* @throws NotFoundException
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
protected function getRelevantMessagePart(string $message, string $search): string {
|
protected function getRelevantMessagePart(string $message, string $search): string {
|
||||||
$start = stripos($message, $search);
|
$start = mb_stripos($message, $search);
|
||||||
if ($start === false) {
|
if ($start === false) {
|
||||||
throw new NotFoundException('Comment section not found');
|
throw new NotFoundException('Comment section not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$end = $start + strlen($search);
|
$end = $start + mb_strlen($search);
|
||||||
|
|
||||||
if ($start <= 25) {
|
if ($start <= 25) {
|
||||||
$start = 0;
|
$start = 0;
|
||||||
|
@ -97,15 +97,15 @@ class Result extends BaseResult {
|
||||||
$prefix = '…';
|
$prefix = '…';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((strlen($message) - $end) <= 25) {
|
if ((mb_strlen($message) - $end) <= 25) {
|
||||||
$end = strlen($message);
|
$end = mb_strlen($message);
|
||||||
$suffix = '';
|
$suffix = '';
|
||||||
} else {
|
} else {
|
||||||
$end += 25;
|
$end += 25;
|
||||||
$suffix = '…';
|
$suffix = '…';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $prefix . substr($message, $start, $end - $start) . $suffix;
|
return $prefix . mb_substr($message, $start, $end - $start) . $suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue