Skip to content

Commit

Permalink
Stricter parsing of string_continue escapes in cooked string
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 24, 2023
1 parent 7ef071f commit 10bbe3f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ fn cooked_string(input: Cursor) -> Result<Cursor, Reject> {
return Err(Reject);
}
match chars.peek() {
Some((_, ch)) if ch.is_whitespace() => {
Some((_, ch @ ' ')) | Some((_, ch @ '\t')) | Some((_, ch @ '\n'))
| Some((_, ch @ '\r')) => {
last = *ch;
chars.next();
}
Expand Down Expand Up @@ -451,7 +452,10 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> {
return Err(Reject);
}
match chars.next() {
Some((_, ch)) if ch.is_whitespace() => last = ch,
Some((_, ch @ ' ')) | Some((_, ch @ '\t')) | Some((_, ch @ '\n'))
| Some((_, ch @ '\r')) => {
last = ch;
}
Some((offset, _)) => {
input = rest.advance(offset);
bytes = input.bytes().enumerate();
Expand Down
3 changes: 1 addition & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn literal_byte_string() {

"b\"\\\r\n x\"".parse::<TokenStream>().unwrap();
"b\"\\\r\n \rx\"".parse::<TokenStream>().unwrap_err();
"b\"\\\r\n \u{a0}x\"".parse::<TokenStream>().unwrap(); // FIXME
"b\"\\\r\n \u{a0}x\"".parse::<TokenStream>().unwrap_err();
}

#[test]
Expand Down Expand Up @@ -664,7 +664,6 @@ fn non_ascii_tokens() {
check_spans("ábc// foo", &[(1, 0, 1, 3)]);
check_spans("ábć// foo", &[(1, 0, 1, 3)]);
check_spans("b\"a\\\n c\"", &[(1, 0, 2, 3)]);
check_spans("b\"a\\\n\u{00a0}c\"", &[(1, 0, 2, 3)]);
}

#[cfg(span_locations)]
Expand Down

0 comments on commit 10bbe3f

Please sign in to comment.