Skip to content

Commit

Permalink
fix: case-insensitivity in the like() method when in use with accente…
Browse files Browse the repository at this point in the history
…d characters
  • Loading branch information
michalsn committed Oct 25, 2024
1 parent 11d9721 commit c36e0d9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ protected function _like($field, string $match = '', string $type = 'AND ', stri

foreach ($keyValue as $k => $v) {
if ($insensitiveSearch === true) {
$v = strtolower($v);
$v = mb_strtolower($v);
}

$prefix = empty($this->{$clause}) ? $this->groupGetType('') : $this->groupGetType($type);
Expand Down
4 changes: 4 additions & 0 deletions tests/_support/Database/Seeds/CITestSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public function run(): void
'key' => 'key',
'value' => 'value',
],
[
'key' => 'accented characters',
'value' => 'śćźżłąęó',
],
],
'type_test' => [
[
Expand Down
8 changes: 8 additions & 0 deletions tests/system/Database/Live/LikeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public function testLikeCaseInsensitive(): void
$this->assertSame('Developer', $job->name);
}

public function testLikeCaseInsensitiveWithAccentedCharacter(): void
{
$wai = $this->db->table('without_auto_increment')->like('value', 'ŁĄ', 'both', null, true)->get();
$wai = $wai->getRow();

$this->assertSame('accented characters', $wai->key);
}

public function testOrLike(): void
{
$jobs = $this->db->table('job')->like('name', 'ian')
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.5.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Bugs Fixed
- **Session Library:** The session initialization debug message now uses the correct log type "debug" instead of "info".

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

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

0 comments on commit c36e0d9

Please sign in to comment.