Skip to content

Commit 2b490c1

Browse files
authored
[5.x] Fix case insensitive Comb search for UTF-8 characters (#11363)
1 parent 36c3b22 commit 2b490c1

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/Search/Comb/Comb.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,11 @@ private function searchOverData($params, $raw_query)
539539
$escaped_chunk = preg_quote($chunk, '#');
540540
$chunk_is_word = ! preg_match('#\s#', $chunk);
541541
$regex = [
542-
'partial_anywhere' => '#'.$escaped_chunk.'#i',
543-
'partial_from_start_anywhere' => '#(^|\s)'.$escaped_chunk.'#i',
544-
'whole_anywhere' => '#(^|\s)'.$escaped_chunk.'($|\s)#i',
545-
'partial_from_start' => '#^'.$escaped_chunk.'#i',
546-
'whole' => '#^'.$escaped_chunk.'$#i',
542+
'partial_anywhere' => '#'.$escaped_chunk.'#iu',
543+
'partial_from_start_anywhere' => '#(^|\s)'.$escaped_chunk.'#iu',
544+
'whole_anywhere' => '#(^|\s)'.$escaped_chunk.'($|\s)#iu',
545+
'partial_from_start' => '#^'.$escaped_chunk.'#iu',
546+
'whole' => '#^'.$escaped_chunk.'$#iu',
547547
];
548548

549549
// loop over each data property
@@ -710,8 +710,8 @@ private function searchOverData($params, $raw_query)
710710
*/
711711
private function removeDisallowedMatches($params)
712712
{
713-
$disallowed = '#'.implode('|', $params['disallowed']).'#i';
714-
$required = '#(?=.*'.implode(')(?=.*', $params['required']).')#i';
713+
$disallowed = '#'.implode('|', $params['disallowed']).'#iu';
714+
$required = '#(?=.*'.implode(')(?=.*', $params['required']).')#iu';
715715
$new_data = [];
716716

717717
// this only applies to boolean mode
@@ -1058,7 +1058,7 @@ private function extractSnippets($value, $chunks)
10581058
$escaped_chunks = collect($chunks)
10591059
->map(fn ($chunk) => preg_quote($chunk, '#'))
10601060
->join('|');
1061-
$regex = '#(.*?)('.$escaped_chunks.')(.{0,'.$length.'}(?:\s|$))#i';
1061+
$regex = '#(.*?)('.$escaped_chunks.')(.{0,'.$length.'}(?:\s|$))#iu';
10621062
if (! preg_match_all($regex, $value, $matches, PREG_SET_ORDER)) {
10631063
return [];
10641064
}
@@ -1081,7 +1081,7 @@ private function extractSnippets($value, $chunks)
10811081
}
10821082
$snippets[] = trim($snippet);
10831083
}
1084-
if (preg_match('#('.$escaped_chunks.')#i', $surplus)) {
1084+
if (preg_match('#('.$escaped_chunks.')#iu', $surplus)) {
10851085
$snippets[] = trim($surplus);
10861086
}
10871087

tests/Search/CombTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ public function it_can_search_for_slashes()
239239
$this->assertSame(1, $result['info']['total_results']);
240240
}
241241

242+
#[Test]
243+
public function it_can_search_for_umlauts()
244+
{
245+
$comb = new Comb([
246+
['content' => 'Üppercase umlaut'],
247+
['content' => 'Lowercase ümlaut'],
248+
]);
249+
250+
$result = $comb->lookUp('ü');
251+
$this->assertIsArray($result);
252+
$this->assertCount(2, $result);
253+
$this->assertSame(2, $result['info']['total_results']);
254+
}
255+
242256
public static function searchesProvider()
243257
{
244258
return [

0 commit comments

Comments
 (0)