Skip to content

Commit c36e0d9

Browse files
committed
fix: case-insensitivity in the like() method when in use with accented characters
1 parent 11d9721 commit c36e0d9

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

system/Database/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ protected function _like($field, string $match = '', string $type = 'AND ', stri
11511151

11521152
foreach ($keyValue as $k => $v) {
11531153
if ($insensitiveSearch === true) {
1154-
$v = strtolower($v);
1154+
$v = mb_strtolower($v);
11551155
}
11561156

11571157
$prefix = empty($this->{$clause}) ? $this->groupGetType('') : $this->groupGetType($type);

tests/_support/Database/Seeds/CITestSeeder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public function run(): void
8686
'key' => 'key',
8787
'value' => 'value',
8888
],
89+
[
90+
'key' => 'accented characters',
91+
'value' => 'śćźżłąęó',
92+
],
8993
],
9094
'type_test' => [
9195
[

tests/system/Database/Live/LikeTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ public function testLikeCaseInsensitive(): void
7575
$this->assertSame('Developer', $job->name);
7676
}
7777

78+
public function testLikeCaseInsensitiveWithAccentedCharacter(): void
79+
{
80+
$wai = $this->db->table('without_auto_increment')->like('value', 'ŁĄ', 'both', null, true)->get();
81+
$wai = $wai->getRow();
82+
83+
$this->assertSame('accented characters', $wai->key);
84+
}
85+
7886
public function testOrLike(): void
7987
{
8088
$jobs = $this->db->table('job')->like('name', 'ian')

user_guide_src/source/changelogs/v4.5.6.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Bugs Fixed
3232
- **Session Library:** The session initialization debug message now uses the correct log type "debug" instead of "info".
3333

3434
- **Validation:** Fixed the `getValidated()` method that did not return valid data when validation rules used multiple asterisks.
35+
- **Database:** Fixed the case insensitivity option in the ``like()`` method when dealing with accented characters.
3536

3637
See the repo's
3738
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)