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

test: verify that invalid string literals in LIKE expression are a parse error #1280

Merged
merged 1 commit into from
May 22, 2024

Conversation

Cali0707
Copy link
Contributor

@Cali0707 Cali0707 commented May 9, 2024

Follow up on discussion in sdk-go: cloudevents/sdk-go#1046 (comment)

Proposed Changes

  • Add a test verifying that an invalid string literal in a LIKE expression is a parse error

…rse error

Signed-off-by: Calum Murray <cmurray@redhat.com>
@Cali0707
Copy link
Contributor Author

Cali0707 commented May 9, 2024

cc @duglin @pierDipi

@@ -116,3 +116,10 @@ tests:
- name: With type coercion from bool (4)
expression: "FALSE LIKE 'fal%'"
result: true

- name: Invalid string literal in comparison causes parse error
expression: "x LIKE 123"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doesn't say that % is required, so why is this an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the only valid string literals in CESQL are either single quoted or double quoted. So, since 123 is not quoted it is not a string literal. See the definition for LIKE here:

string-literal ::= ( "'" ( [^'] | "\'" )* "'" ) | ( '"' ( [^"] | '\"' )* '"')
like-operator ::= "LIKE"
not-operator ::= "NOT"
like-operation ::= expression not-operator? like-operator string-literal

Basically, the LIKE operator is ONLY defined where the right hand operand is a string literal, and string literals require a single or double quote

@Cali0707 Cali0707 requested a review from duglin May 20, 2024 22:48
@duglin
Copy link
Collaborator

duglin commented May 22, 2024

LGTM

@duglin
Copy link
Collaborator

duglin commented May 22, 2024

Approved on the 5/16 call

@duglin duglin merged commit d697a87 into cloudevents:main May 22, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants