Skip to content

Commit

Permalink
[update] Improve operator matching and will throw error for invalid o…
Browse files Browse the repository at this point in the history
…perator. #1021
  • Loading branch information
Angelaon committed Dec 10, 2021
1 parent 992d085 commit 8ab1206
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Medoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ protected function dataImplode(array $data, array &$map, string $conjunctor): st
$isIndex = is_int($key);

preg_match(
'/([\p{L}_][\p{L}\p{N}@$#\-_\.]*)(\[(?<operator>\>\=?|\<\=?|\=|\!\=?|\<\>|\>\<|\!?~|REGEXP)\])?([\p{L}_][\p{L}\p{N}@$#\-_\.]*)?/u',
'/([\p{L}_][\p{L}\p{N}@$#\-_\.]*)(\[(?<operator>.*)\])?([\p{L}_][\p{L}\p{N}@$#\-_\.]*)?/u',
$isIndex ? $value : $key,
$match
);
Expand All @@ -869,7 +869,7 @@ protected function dataImplode(array $data, array &$map, string $conjunctor): st
continue;
}

if ($operator) {
if ($operator && $operator != '=') {
if (in_array($operator, ['>', '>=', '<', '<='])) {
$condition = "{$column} {$operator} ";

Expand Down Expand Up @@ -965,6 +965,8 @@ protected function dataImplode(array $data, array &$map, string $conjunctor): st
} elseif ($operator === 'REGEXP') {
$stack[] = "{$column} REGEXP {$mapKey}";
$map[$mapKey] = [$value, PDO::PARAM_STR];
} else {
throw new InvalidArgumentException("Invalid operator [{$operator}] for column {$column} supplied.");
}

continue;
Expand Down

0 comments on commit 8ab1206

Please sign in to comment.