Skip to content

Commit

Permalink
Fix broken LIKE escaping (#898)
Browse files Browse the repository at this point in the history
* Fix broken LIKE escaping
  • Loading branch information
GrahamCampbell committed Oct 5, 2023
1 parent 054fda6 commit a91a348
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Filters/FiltersPartial.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ public function __invoke(Builder $query, $value, string $property)

protected function getWhereRawParameters($value, string $property): array
{
$value = mb_strtolower($value, 'UTF8');
$value = mb_strtolower((string) $value, 'UTF8');

return [
"LOWER({$property}) LIKE ?",
["%{$value}%"],
['%'.self::escapeLike($value).'%'],
];
}

private static function escapeLike(string $value): string
{
return str_replace(
['\\', '_', '%'],
['\\\\', '\\_', '\\%'],
$value,
);
}
}

0 comments on commit a91a348

Please sign in to comment.