Skip to content

Commit eca5b86

Browse files
authored
Merge pull request apache#7 from zhyass/main
Process escape character in quoted string
2 parents 699fddd + 42bf210 commit eca5b86

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/ast/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,14 @@ impl fmt::Display for WindowSpec {
433433
write!(f, "ORDER BY {}", display_comma_separated(&self.order_by))?;
434434
}
435435
if let Some(window_frame) = &self.window_frame {
436+
f.write_str(delim)?;
436437
if let Some(end_bound) = &window_frame.end_bound {
437-
f.write_str(delim)?;
438438
write!(
439439
f,
440440
"{} BETWEEN {} AND {}",
441441
window_frame.units, window_frame.start_bound, end_bound
442442
)?;
443443
} else {
444-
f.write_str(delim)?;
445444
write!(f, "{} {}", window_frame.units, window_frame.start_bound)?;
446445
}
447446
}

src/parser.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1620,9 +1620,10 @@ impl<'a> Parser<'a> {
16201620
loop {
16211621
if let Some(constraint) = self.parse_optional_table_constraint()? {
16221622
constraints.push(constraint);
1623-
} else if let Token::Word(_) = self.peek_token() {
1624-
columns.push(self.parse_column_def()?);
1625-
} else if let Token::BackQuotedString(_) = self.peek_token() {
1623+
} else if matches!(
1624+
self.peek_token(),
1625+
Token::Word(_) | Token::BackQuotedString(_)
1626+
) {
16261627
columns.push(self.parse_column_def()?);
16271628
} else {
16281629
return self.expected("column name or constraint definition", self.peek_token());
@@ -2793,10 +2794,10 @@ impl<'a> Parser<'a> {
27932794
// followed by some joins or (B) another level of nesting.
27942795
let mut table_and_joins = self.parse_table_and_joins()?;
27952796

2796-
if !table_and_joins.joins.is_empty() {
2797-
self.expect_token(&Token::RParen)?;
2798-
Ok(TableFactor::NestedJoin(Box::new(table_and_joins))) // (A)
2799-
} else if let TableFactor::NestedJoin(_) = &table_and_joins.relation {
2797+
if !table_and_joins.joins.is_empty()
2798+
|| matches!(&table_and_joins.relation, TableFactor::NestedJoin(_))
2799+
{
2800+
// (A)
28002801
// (B): `table_and_joins` (what we found inside the parentheses)
28012802
// is a nested join `(foo JOIN bar)`, not followed by other joins.
28022803
self.expect_token(&Token::RParen)?;

src/tokenizer.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,9 @@ impl<'a> Tokenizer<'a> {
643643
) -> Result<String, TokenizerError> {
644644
let mut s = String::new();
645645
chars.next(); // consume the opening quote
646-
while let Some(&ch) = chars.peek() {
646+
while let Some(ch) = chars.next() {
647647
match ch {
648648
'\'' => {
649-
chars.next(); // consume
650649
let escaped_quote = chars.peek().map(|c| *c == '\'').unwrap_or(false);
651650
if escaped_quote {
652651
s.push('\'');
@@ -655,8 +654,25 @@ impl<'a> Tokenizer<'a> {
655654
return Ok(s);
656655
}
657656
}
657+
'\\' => {
658+
if let Some(c) = chars.next() {
659+
match c {
660+
'n' => s.push('\n'),
661+
't' => s.push('\t'),
662+
'r' => s.push('\r'),
663+
'b' => s.push('\u{08}'),
664+
'0' => s.push('\0'),
665+
'\'' => s.push('\''),
666+
'\\' => s.push('\\'),
667+
'\"' => s.push('\"'),
668+
_ => {
669+
s.push('\\');
670+
s.push(c);
671+
}
672+
}
673+
}
674+
}
658675
_ => {
659-
chars.next(); // consume
660676
s.push(ch);
661677
}
662678
}

0 commit comments

Comments
 (0)