-
Notifications
You must be signed in to change notification settings - Fork 755
Escape closing brackets in bracket-quoted identifiers #2418
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
Open
hdimer
wants to merge
2
commits into
apache:main
Choose a base branch
from
hdimer:fix/2409-bracket-ident-escape
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+55
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -937,6 +937,32 @@ fn parse_table_name_in_square_brackets() { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_bracket_identifier_with_escaped_closing_bracket() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing is insufficient and the proposed changes are currently regressing working cases. For instance, in unescaped mode, |
||
| // A `]` inside a bracket-quoted identifier is escaped by doubling it, so | ||
| // `[a]]b]` denotes the identifier `a]b`. | ||
| let select = ms().verified_only_select("SELECT [a]]b]"); | ||
| assert_eq!( | ||
| &Expr::Identifier(Ident::with_quote('[', "a]b")), | ||
| expr_from_projection(&select.projection[0]), | ||
| ); | ||
|
|
||
| // Round-trips regardless of where the escaped `]` sits. | ||
| for sql in [ | ||
| "SELECT [a]]b] FROM [c]]d]", | ||
| "SELECT []]]", // the identifier is a single `]` | ||
| "SELECT [a]]]", // trailing `]` | ||
| "SELECT []]b]", // leading `]` | ||
| "SELECT [a]]b]]c]", // several escaped `]` | ||
| ] { | ||
| ms().verified_stmt(sql); | ||
| } | ||
|
|
||
| // In no-escape mode the parsed value keeps the raw `]]`, so serializing it | ||
| // must not double the brackets again. | ||
| ms_no_unescape().verified_stmt("SELECT [a]]b]"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_for_clause() { | ||
| ms_and_generic().verified_stmt("SELECT a FROM t FOR JSON PATH"); | ||
|
|
@@ -2435,6 +2461,13 @@ fn ms() -> TestedDialects { | |
| TestedDialects::new(vec![Box::new(MsSqlDialect {})]) | ||
| } | ||
|
|
||
| fn ms_no_unescape() -> TestedDialects { | ||
| TestedDialects::new_with_options( | ||
| vec![Box::new(MsSqlDialect {})], | ||
| ParserOptions::new().with_unescape(false), | ||
| ) | ||
| } | ||
|
|
||
| // MS SQL dialect with support for optional semi-colon statement delimiters | ||
| fn tsql() -> TestedDialects { | ||
| TestedDialects::new_with_options( | ||
|
|
||
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.
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.
I believe there are several other cases where the current solution fails, other than the one I reported in the test comment. I suggest you fuzz with seeding/use round trip prop tests this code before pushing the next iteration of your PR, since it would have most likely immediately caught the mentioned problems, even if you vibe code this thing using AI. It is a very effective support tool when you lean on code generation, as it gives you test inputs generation and invariant testing.