-
Notifications
You must be signed in to change notification settings - Fork 721
fix: handle escaped backslashes in SQL string literals #838
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -245,3 +245,21 @@ def test_cli_commands(): | |||||
| p = sqlparse.parse('\\copy')[0] | ||||||
| assert len(p.tokens) == 1 | ||||||
| assert p.tokens[0].ttype == T.Command | ||||||
|
|
||||||
|
|
||||||
| def test_tokenize_escaped_backslash(): | ||||||
| """Test that escaped backslashes in SQL strings are correctly tokenized.""" | ||||||
| import sqlparse | ||||||
| from sqlparse import tokens as T | ||||||
|
Comment on lines
+252
to
+253
|
||||||
| import sqlparse | |
| from sqlparse import tokens as T |
Copilot
AI
Feb 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comment describing the expected token sequence is incorrect/garbled (it mentions commas/quotes in a way that doesn’t match the SQL). Please update it to reflect the actual expected flattened token order for SELECT '\\', '\\' to avoid misleading future readers.
| # Should be: SELECT, whitespace, ',', ,, whitespace, ',', (6 tokens after keyword) | |
| # Expected flattened token order: SELECT, <WS>, "'\\'", ',', <WS>, "'\\'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR also changes the double-quoted pattern, but the added test only covers single-quoted strings. Please add a regression test exercising a double-quoted value containing escaped backslashes (and verifying tokenization doesn’t produce
T.Error/ doesn’t merge tokens) so the\\addition here is covered.