robertogallok opened a new pull request, #2523:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2523
`Ident::Display` reuses the string-literal escaper, which guesses whether a
delimiter inside the value is already escaped. An `Ident` value is always the
decoded name, so the guess corrupts identifiers whose name contains two
adjacent delimiters or a backslash before one:
```rust
let ast = Parser::parse_sql(&GenericDialect {}, r#"SELECT
"a""""b""#).unwrap(); // identifier a""b
println!("{}", ast[0]); // SELECT "a""b" -> parses back as the
identifier a"b
```
The same happens with backticks (`` `a````b` ``) and with a value such as
`a\"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
one `Display` cannot 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 on `main` (smallest failing value: `""`).
AI assistance was used to draft this change; I reviewed and ran the tests,
`cargo fmt` and `cargo clippy`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]