Escape every delimiter when displaying quoted identifiers - #2523
Open
robertogallok wants to merge 1 commit into
Open
robertogallok wants to merge 1 commit into
robertogallok wants to merge 1 commit into
Conversation
The tokenizer decodes doubled delimiters, so an Ident value holds the literal name. Ident::Display reused the string-literal escaper, whose heuristic leaves adjacent delimiters and backslash-preceded delimiters untouched; a value such as a""b displayed as "a""b", which parses as a different identifier. Double each delimiter unconditionally, without allocating. The two MySQL tests that asserted a display round trip in no-escape mode now assert only the parsed AST, since a value that keeps its raw escapes cannot share one Display with a decoded one.
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.
Ident::Displayreuses the string-literal escaper, which guesses whether a delimiter inside the value is already escaped. AnIdentvalue is always the decoded name, so the guess corrupts identifiers whose name contains two adjacent delimiters or a backslash before one:The same happens with backticks (
`a````b`) and with a value such asa\"b, which displays as"a\"b"and no longer parses.The fix doubles every delimiter unconditionally, streaming into the formatter without allocating. Bracket identifiers are left untouched because #2418 already covers them.
with_unescape(false)keeps the raw doubled delimiters in the value, and oneDisplaycannot serve both readings of the same value. This change chooses the default mode, so the two MySQL tests that asserted a display round trip in no-escape mode now assert only the parsed AST.Tests: a round trip for consecutive delimiters in
"and`identifiers, plus an exhaustive round trip over every value of length 1..=4 built from the delimiter, a backslash, an ASCII and a multi-byte character, across all dialects that delimit identifiers with that character. The exhaustive test fails onmain(smallest failing value:"").AI assistance was used to draft this change; I reviewed and ran the tests,
cargo fmtandcargo clippy.