Skip to content

Commit a922484

Browse files
committed
Fix lexing of EOF in unterminated string
1 parent c229843 commit a922484

10 files changed

+17
-35
lines changed

crates/apollo-parser/CHANGELOG.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2525
Stack overflow was observed with little more than 2000
2626
nesting levels or repetitions in the new test.
2727
Defaulting to a quarter of that leaves a comfortable margin.
28-
- **fixes lexing of plus and minus signs in numbers - [SimonSapin], [pull/646]**
29-
Plus signs are errors in GraphQL syntax.
30-
Minus signs are errors if they’re not followed by a digit, even if followed by EOF.
28+
- **fix various lexer bugs - [SimonSapin], [pull/646], [pull/652]**
29+
The lexer was too permissive in emitting tokens instead of errors
30+
in various cases around numbers, strings, and EOF.
3131

3232
[pull/646]: https://github.com/apollographql/apollo-rs/pull/646
33+
[pull/652]: https://github.com/apollographql/apollo-rs/pull/652
3334
[pull/662]: https://github.com/apollographql/apollo-rs/pull/662
3435
[Issue 666]: https://github.com/apollographql/apollo-rs/issues/666
3536

crates/apollo-parser/src/lexer/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,11 @@ impl<'a> Cursor<'a> {
535535
curr.to_string(),
536536
))
537537
}
538-
State::StringLiteral | State::BlockStringLiteral => {
538+
State::StringLiteral
539+
| State::BlockStringLiteral
540+
| State::StringLiteralEscapedUnicode(_)
541+
| State::BlockStringLiteralBackslash
542+
| State::StringLiteralBackslash => {
539543
let curr = self.drain();
540544

541545
Err(Error::with_loc(
@@ -556,9 +560,6 @@ impl<'a> Cursor<'a> {
556560
))
557561
}
558562
State::Ident
559-
| State::StringLiteralEscapedUnicode(_)
560-
| State::BlockStringLiteralBackslash
561-
| State::StringLiteralBackslash
562563
| State::LeadingZero
563564
| State::IntegerPart
564565
| State::FractionalPart
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
` # Artificial error
21
"\
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
ERROR@0:1 "Unexpected character \"`\"" `
2-
WHITESPACE@1:2 " "
3-
COMMENT@2:20 "# Artificial error"
4-
WHITESPACE@20:21 "\n"
5-
STRING_VALUE@21:23 "\"\\"
6-
EOF@23:23
1+
ERROR@0:2 "unterminated string value" "\
2+
EOF@2:2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
` # Artificial error
21
"\u
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
ERROR@0:1 "Unexpected character \"`\"" `
2-
WHITESPACE@1:2 " "
3-
COMMENT@2:20 "# Artificial error"
4-
WHITESPACE@20:21 "\n"
5-
STRING_VALUE@21:24 "\"\\u"
6-
EOF@24:24
1+
ERROR@0:3 "unterminated string value" "\u
2+
EOF@3:3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
` # Artificial error
21
"\u222
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
ERROR@0:1 "Unexpected character \"`\"" `
2-
WHITESPACE@1:2 " "
3-
COMMENT@2:20 "# Artificial error"
4-
WHITESPACE@20:21 "\n"
5-
STRING_VALUE@21:27 "\"\\u222"
6-
EOF@27:27
1+
ERROR@0:6 "unterminated string value" "\u222
2+
EOF@6:6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
` # Artificial error
21
"""\
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
ERROR@0:1 "Unexpected character \"`\"" `
2-
WHITESPACE@1:2 " "
3-
COMMENT@2:20 "# Artificial error"
4-
WHITESPACE@20:21 "\n"
5-
STRING_VALUE@21:25 "\"\"\"\\"
6-
EOF@25:25
1+
ERROR@0:4 "unterminated string value" """\
2+
EOF@4:4

0 commit comments

Comments
 (0)