Skip to content

Commit

Permalink
[String] LIKE properly escapes regexp-characters (#156)
Browse files Browse the repository at this point in the history
* [String] `LIKE` properly escapes regexp-characters

* remove unused import
  • Loading branch information
ohaibbq authored Mar 9, 2024
1 parent 4505d46 commit 5f9498b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func LIKE(a, b Value) (Value, error) {
if err != nil {
return nil, err
}
wildcard := strings.Replace(vb, "%", ".*", -1)
wildcard := strings.Replace(regexp.QuoteMeta(vb), "%", ".*", -1)
matchLimits := fmt.Sprintf("^%s$", wildcard)
re, err := regexp.Compile(matchLimits)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ func TestQuery(t *testing.T) {
query: `SELECT "abcd" LIKE "a%d"`,
expectedRows: [][]interface{}{{true}},
},
{
name: "like operator - special regex characters",
query: `SELECT 'my*string' LIKE '%%*%%', 'my*string' LIKE '%%([][%';`,
expectedRows: [][]interface{}{{true, false}},
},
{
name: "like operator2",
query: `SELECT "abcd" LIKE "%a%"`,
Expand Down

0 comments on commit 5f9498b

Please sign in to comment.