Skip to content

Commit a91a348

Browse files
Fix broken LIKE escaping (#898)
* Fix broken LIKE escaping
1 parent 054fda6 commit a91a348

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Filters/FiltersPartial.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,20 @@ public function __invoke(Builder $query, $value, string $property)
4444

4545
protected function getWhereRawParameters($value, string $property): array
4646
{
47-
$value = mb_strtolower($value, 'UTF8');
47+
$value = mb_strtolower((string) $value, 'UTF8');
4848

4949
return [
5050
"LOWER({$property}) LIKE ?",
51-
["%{$value}%"],
51+
['%'.self::escapeLike($value).'%'],
5252
];
5353
}
54+
55+
private static function escapeLike(string $value): string
56+
{
57+
return str_replace(
58+
['\\', '_', '%'],
59+
['\\\\', '\\_', '\\%'],
60+
$value,
61+
);
62+
}
5463
}

0 commit comments

Comments
 (0)