This is an automated email from the ASF dual-hosted git repository. LucaCappelletti94 pushed a commit to branch hex-string-literal-quote-escaping in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit 36f51668cb4fb23c0e7dd271f89b1d5e9c881e93 Author: LucaCappelletti94 <[email protected]> AuthorDate: Tue Sep 22 11:19:35 2026 +0200 Generic: Fix quote escaping when displaying hex string literals --- src/ast/value.rs | 14 +++++++++++++- tests/sqlparser_common.rs | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ast/value.rs b/src/ast/value.rs index a906c4b3..ad5dd1ab 100644 --- a/src/ast/value.rs +++ b/src/ast/value.rs @@ -276,7 +276,7 @@ impl fmt::Display for Value { Value::NationalStringLiteral(v) => write!(f, "N'{}'", escape_single_quote_string(v)), Value::QuoteDelimitedStringLiteral(v) => v.fmt(f), Value::NationalQuoteDelimitedStringLiteral(v) => write!(f, "N{v}"), - Value::HexStringLiteral(v) => write!(f, "X'{v}'"), + Value::HexStringLiteral(v) => write!(f, "X'{}'", escape_single_quote_string(v)), Value::Boolean(v) => write!(f, "{v}"), Value::SingleQuotedByteStringLiteral(v) => write!(f, "B'{v}'"), Value::DoubleQuotedByteStringLiteral(v) => write!(f, "B\"{v}\""), @@ -717,3 +717,15 @@ fn test_escape_quoted_string_with_multibyte_quote_char() { "a🦀🦀b🦀🦀c" ); } +#[cfg(test)] +#[test] +fn test_hex_string_literal_display_escaping() { + assert_eq!( + Value::HexStringLiteral("'".to_string()).to_string(), + "X''''" + ); + assert_eq!( + Value::HexStringLiteral("it's".to_string()).to_string(), + "X'it''s'" + ); +} diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index c4aa607d..14ed2c52 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -20080,3 +20080,10 @@ fn parse_unary_minus_never_renders_line_comment() { all_dialects().verified_stmt("SELECT -1"); all_dialects().verified_stmt("SELECT -x"); } + +#[test] +fn parse_hex_string_literal_display_escaping() { + all_dialects().verified_stmt("SELECT X''''"); + all_dialects().verified_stmt("SELECT X'ab''cd'"); + all_dialects().one_statement_parses_to("SELECT x'''' N", "SELECT X'''' AS N"); +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
