Skip to content

Commit 10bbe3f

Browse files
committed
Stricter parsing of string_continue escapes in cooked string
1 parent 7ef071f commit 10bbe3f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/parse.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ fn cooked_string(input: Cursor) -> Result<Cursor, Reject> {
396396
return Err(Reject);
397397
}
398398
match chars.peek() {
399-
Some((_, ch)) if ch.is_whitespace() => {
399+
Some((_, ch @ ' ')) | Some((_, ch @ '\t')) | Some((_, ch @ '\n'))
400+
| Some((_, ch @ '\r')) => {
400401
last = *ch;
401402
chars.next();
402403
}
@@ -451,7 +452,10 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> {
451452
return Err(Reject);
452453
}
453454
match chars.next() {
454-
Some((_, ch)) if ch.is_whitespace() => last = ch,
455+
Some((_, ch @ ' ')) | Some((_, ch @ '\t')) | Some((_, ch @ '\n'))
456+
| Some((_, ch @ '\r')) => {
457+
last = ch;
458+
}
455459
Some((offset, _)) => {
456460
input = rest.advance(offset);
457461
bytes = input.bytes().enumerate();

tests/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn literal_byte_string() {
162162

163163
"b\"\\\r\n x\"".parse::<TokenStream>().unwrap();
164164
"b\"\\\r\n \rx\"".parse::<TokenStream>().unwrap_err();
165-
"b\"\\\r\n \u{a0}x\"".parse::<TokenStream>().unwrap(); // FIXME
165+
"b\"\\\r\n \u{a0}x\"".parse::<TokenStream>().unwrap_err();
166166
}
167167

168168
#[test]
@@ -664,7 +664,6 @@ fn non_ascii_tokens() {
664664
check_spans("ábc// foo", &[(1, 0, 1, 3)]);
665665
check_spans("ábć// foo", &[(1, 0, 1, 3)]);
666666
check_spans("b\"a\\\n c\"", &[(1, 0, 2, 3)]);
667-
check_spans("b\"a\\\n\u{00a0}c\"", &[(1, 0, 2, 3)]);
668667
}
669668

670669
#[cfg(span_locations)]

0 commit comments

Comments
 (0)