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 17:58:46 UTC

(datafusion-sqlparser-rs) branch gh-readonly-queue/main/pr-2544-1aeaba51f51b8b857be6922ee2da857698330834 created (now 5d5d3ba53)

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

github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-2544-1aeaba51f51b8b857be6922ee2da857698330834
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


      at 5d5d3ba53 Escape quotes when displaying `Word` tokens (#2544)

This branch includes the following new commits:

     new 5d5d3ba53 Escape quotes when displaying `Word` tokens (#2544)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org


(datafusion-sqlparser-rs) 01/01: Escape quotes when displaying `Word` tokens (#2544)

Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5d5d3ba53cca1d82dab06d5d00bf9c38488ac490
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Tue Sep 22 17:58:21 2026 +0000

    Escape quotes when displaying `Word` tokens (#2544)
---
 src/ast/mod.rs               | 25 ++++++++++++++++---------
 src/tokenizer.rs             | 39 ++++++++++++++++++++++++++++++++-------
 tests/sqlparser_snowflake.rs |  7 +++++++
 3 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 92a0f92a5..85344da92 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -378,17 +378,24 @@ impl From<&str> for Ident {
     }
 }
 
+pub(crate) fn fmt_ident(
+    f: &mut fmt::Formatter,
+    value: &str,
+    quote_style: Option<char>,
+) -> fmt::Result {
+    match quote_style {
+        Some('[') => write!(f, "[{value}]"),
+        Some(q) => {
+            let escaped = value::escape_quoted_string(value, q);
+            write!(f, "{q}{escaped}{q}")
+        }
+        None => f.write_str(value),
+    }
+}
+
 impl fmt::Display for Ident {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self.quote_style {
-            Some(q) if q == '"' || q == '\'' || q == '`' => {
-                let escaped = value::escape_quoted_string(&self.value, q);
-                write!(f, "{q}{escaped}{q}")
-            }
-            Some('[') => write!(f, "[{}]", self.value),
-            None => f.write_str(&self.value),
-            _ => panic!("unexpected quote style"),
-        }
+        fmt_ident(f, &self.value, self.quote_style)
     }
 }
 
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 36a3abf06..e17433e5d 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -470,13 +470,7 @@ pub struct Word {
 
 impl fmt::Display for Word {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match self.quote_style {
-            Some(s) if s == '"' || s == '[' || s == '`' => {
-                write!(f, "{}{}{}", s, self.value, Word::matching_end_quote(s))
-            }
-            None => f.write_str(&self.value),
-            _ => panic!("Unexpected quote_style!"),
-        }
+        crate::ast::fmt_ident(f, &self.value, self.quote_style)
     }
 }
 
@@ -4552,4 +4546,35 @@ mod tests {
             ],
         );
     }
+
+    #[test]
+    fn test_word_display_quote_escaping() {
+        assert_eq!(
+            Word {
+                value: "a\"b".to_string(),
+                quote_style: Some('"'),
+                keyword: Keyword::NoKeyword,
+            }
+            .to_string(),
+            "\"a\"\"b\""
+        );
+        assert_eq!(
+            Word {
+                value: "a`b".to_string(),
+                quote_style: Some('`'),
+                keyword: Keyword::NoKeyword,
+            }
+            .to_string(),
+            "`a``b`"
+        );
+        assert_eq!(
+            Word {
+                value: "a b".to_string(),
+                quote_style: Some('['),
+                keyword: Keyword::NoKeyword,
+            }
+            .to_string(),
+            "[a b]"
+        );
+    }
 }
diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs
index 059560dcc..2b16ffe5e 100644
--- a/tests/sqlparser_snowflake.rs
+++ b/tests/sqlparser_snowflake.rs
@@ -4912,3 +4912,10 @@ fn test_select_dollar_column_from_stage() {
     // With table function args, without alias
     snowflake().verified_stmt("SELECT $1, $2 FROM @mystage1(file_format => 'myformat')");
 }
+
+#[test]
+fn test_snowflake_stage_name_with_escaped_quotes() {
+    snowflake().verified_stmt("REMOVE @````");
+    snowflake().one_statement_parses_to("RM @````", "REMOVE @````");
+    snowflake().verified_stmt(r#"REMOVE @"stage""name""#);
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org