Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LIKE expression with invalid string literals returns a parse error instead of panicking #1046

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sql/v2/parser/expression_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package parser

import (
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -175,9 +176,13 @@ func (v *expressionVisitor) VisitLikeExpression(ctx *gen.LikeExpressionContext)
if patternContext.DQUOTED_STRING_LITERAL() != nil {
// Parse double quoted string
pattern = dQuotedStringToString(patternContext.DQUOTED_STRING_LITERAL().GetText())
} else {
} else if patternContext.SQUOTED_STRING_LITERAL() != nil {
// Parse single quoted string
pattern = sQuotedStringToString(patternContext.SQUOTED_STRING_LITERAL().GetText())
} else {
// not a string, return an error
v.parsingErrors = append(v.parsingErrors, fmt.Errorf("failed to parse LIKE expression: the pattern was not a string literal"))
return noopExpression{}
}

likeExpression, err := expression.NewLikeExpression(v.Visit(ctx.Expression()).(cesql.Expression), pattern)
Expand Down
9 changes: 8 additions & 1 deletion sql/v2/test/tck/like_expression.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,11 @@ tests:
result: false
- name: With type coercion from bool (4)
expression: "FALSE LIKE 'fal%'"
result: true
result: true
Cali0707 marked this conversation as resolved.
Show resolved Hide resolved

- name: Invalid string literal in comparison causes parse error
expression: "x LIKE 123"
result: false
error: parse
eventOverrides:
x: "123"
Cali0707 marked this conversation as resolved.
Show resolved Hide resolved