LucaCappelletti94 commented on code in PR #2509:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2509#discussion_r4097685996
##########
src/tokenizer.rs:
##########
@@ -2085,6 +2094,33 @@ impl<'a> Tokenizer<'a> {
}
}
+ /// Reads a Unicode string literal body introduced by the `U&` prefix,
e.g. the
+ /// `\0061\0062\0063` in `U&'\0061\0062\0063'`, honoring a trailing
`UESCAPE '<char>'`
+ /// clause if present.
+ /// See
<https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-UESCAPE>
+ fn tokenize_unicode_single_quoted_string(
+ &self,
+ chars: &mut State,
+ ) -> Result<String, TokenizerError> {
+ let error_loc = chars.location();
+ let raw = self.tokenize_single_quoted_string(chars, '\'', false)?;
Review Comment:
You should collapse the doubled quotes when `unescape` is off
```suggestion
let mut raw = self.tokenize_single_quoted_string(chars, '\'',
false)?;
if !self.unescape {
raw = raw.replace("''", "'");
}
```
##########
tests/sqlparser_postgres.rs:
##########
@@ -7205,6 +7205,29 @@ fn test_unicode_string_literal() {
}
}
+#[test]
+fn test_unicode_string_literal_uescape() {
+ // Custom escape character via UESCAPE, see the postgres docs example
+ pg_and_generic().expr_parses_to(r#"U&'d!0061t!+000061' UESCAPE '!'"#,
"U&'data'");
+}
Review Comment:
Just a red test relative to the other note.
```suggestion
}
#[test]
fn test_unicode_string_literal_no_unescape() {
TestedDialects::new_with_options(
vec![Box::new(PostgreSqlDialect {})],
sqlparser::parser::ParserOptions::new().with_unescape(false),
)
.verified_expr("U&'a''b'");
}
```
--
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]