diff --git a/src/Expressions/BinaryOperatorExpression.php b/src/Expressions/BinaryOperatorExpression.php index 9e2daf0..c34111b 100644 --- a/src/Expressions/BinaryOperatorExpression.php +++ b/src/Expressions/BinaryOperatorExpression.php @@ -226,6 +226,9 @@ public function evaluate(row $row, AsyncMysqlConnection $conn): mixed { $pattern = Str\strip_suffix($pattern, '%'); } + // escape all + characters + $pattern = \preg_quote($pattern, '/'); + // replace only unescaped % and _ characters to make regex $pattern = Regex\replace($pattern, re"/(? { $conn = static::$conn as nonnull; $results = await $conn->query( - "SELECT 'foo' LIKE 'foo' as test1, 'foobarbaz' like '%bar%' test2, 'foobaz' LIKE 'foo_az' test3, 'foobarqux' like 'foo%' test4, 'foobarqux' LIKE '%qux' test5, 'blahfoobarbazqux blah' LIKE '%foo%qux%' test6, 'blegh' LIKE '%foo%' test7", + "SELECT 'foo' LIKE 'foo' as test1, 'foobarbaz' like '%bar%' test2, 'foobaz' LIKE 'foo_az' test3, 'foobarqux' like 'foo%' test4, 'foobarqux' LIKE '%qux' test5, 'blahfoobarbazqux blah' LIKE '%foo%qux%' test6, 'blegh' LIKE '%foo%' test7, 'foo+bar' LIKE '%foo+bar%' test8, 'foo/bar' LIKE '%foo/bar%' test9", ); expect($results->rows())->toBeSame( vec[ - dict['test1' => 1, 'test2' => 1, 'test3' => 1, 'test4' => 1, 'test5' => 1, 'test6' => 1, 'test7' => 0], + dict['test1' => 1, 'test2' => 1, 'test3' => 1, 'test4' => 1, 'test5' => 1, 'test6' => 1, 'test7' => 0, 'test8' => 1, 'test9' => 1], ], ); }