You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/09/22 20:35:10 UTC

(datafusion-sqlparser-rs) branch main updated: Generic: Fix quote escaping when displaying hex string literals (#2542)

This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 80751ede1 Generic: Fix quote escaping when displaying hex string literals (#2542)
80751ede1 is described below

commit 80751ede152ef3afeabca910562db559d5459e7e
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Tue Sep 22 20:11:41 2026 +0000

    Generic: Fix quote escaping when displaying hex string literals (#2542)
---
 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 a906c4b3f..ad5dd1ab6 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 4343e652b..722cc1419 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -20121,3 +20121,10 @@ fn parse_table_preserves_quotes_and_trailing_tokens() {
         err
     );
 }
+
+#[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: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org