Fix LIKE operator regex escaping for literal special characters#24
Merged
Fix LIKE operator regex escaping for literal special characters#24
Conversation
The LIKE-to-regex conversion only translated SQL wildcards (% and _) and passed every other character through to RegExp verbatim, so regex-significant characters in the SQL literal produced wrong matches: - LIKE 'user.name@example.com' matched 'userXname@example.com' (dot is any-char) - LIKE 'Books (Fiction)' matched 'Books Fiction' (parens became a capture group) - LIKE 'Price: \$10' compiled to /^Price: \$10\$/i, which matches nothing Escape JS regex metacharacters in the SQL literal before translating the two wildcards. Adds unit coverage for the three failure cases plus % and _ to lock in wildcard semantics against the escape step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed a bug in the LIKE operator implementation where regex metacharacters in SQL patterns were not being properly escaped, causing incorrect matching behavior when patterns contained special characters like dots, parentheses, or dollar signs.
Key Changes
LIKEcase incompiler.tsto escape JavaScript regex metacharacters (.*+?^${}()|[\]\\) before translating SQL wildcards (%and_). This ensures that literal characters in the pattern are matched exactly, while SQL wildcards continue to work as expected.%) functionality_) functionalityImplementation Details
The fix changes the pattern compilation order:
%→.*,_→.) with their regex equivalentsThis ensures that a pattern like
'user.name@example.com'correctly matches only that exact string (with the dot treated literally), while'Jo%'still matches any string starting with "Jo".https://claude.ai/code/session_01SPmihaVijYGP1zqmkfNUyx