Thanks to visit codestin.com
Credit goes to github.com

Skip to content

correctly handle ESCAPE '\'#57

Merged
lu-zhengda merged 1 commit into
mainfrom
zhengda.lu/escape-quote
Apr 11, 2025
Merged

correctly handle ESCAPE '\'#57
lu-zhengda merged 1 commit into
mainfrom
zhengda.lu/escape-quote

Conversation

@lu-zhengda
Copy link
Copy Markdown
Collaborator

Description

Fixed issue #56 where the lexer would incorrectly handle the ESCAPE clause when using a backslash character. Previously, when parsing a query like:

SELECT 1 WHERE 'test_temp_test' LIKE '%\_temp\_%' ESCAPE '\'

The lexer would incorrectly treat '\' as an incomplete string instead of a valid string token containing a single backslash character.

The scanString method was not properly handling the case where a backslash character appears before a quote. In the ESCAPE clause context, the backslash is treated as a literal character rather than an escape character.

Modified the scanString method to track escaped quotes separately from the general escape state. This allows us to:

  1. Properly handle escaped quotes in regular strings (e.g. '\'123')
  2. Correctly parse single backslash characters in ESCAPE clauses (e.g. ESCAPE '\')

Testing

The fix has been verified with test cases covering:

  • ESCAPE clause with backslash: ESCAPE '\'
  • Escaped quotes in strings: '\'123'
  • LIKE patterns with escaped characters: '%\_temp\_%'

@lu-zhengda lu-zhengda requested a review from a team as a code owner April 11, 2025 01:16
@lu-zhengda lu-zhengda merged commit b429cb3 into main Apr 11, 2025
@lu-zhengda lu-zhengda deleted the zhengda.lu/escape-quote branch April 11, 2025 11:33
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.

2 participants