Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require \r whitespace to be followed by \n #393

Merged
merged 3 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ fn skip_whitespace(input: Cursor) -> Cursor {
}
}
match byte {
b' ' | 0x09..=0x0d => {
b' ' | 0x09..=0x0c => {
s = s.advance(1);
continue;
}
b'\r' if s.as_bytes().get(1) == Some(&b'\n') => {
s = s.advance(2);
continue;
}
b if b <= 0x7f => {}
_ => {
let ch = s.chars().next().unwrap();
Expand Down
12 changes: 12 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,18 @@ fn check_spans_internal(ts: TokenStream, lines: &mut &[(usize, usize, usize, usi
}
}

#[test]
fn whitespace() {
// space, horizontal tab, vertical tab, form feed, carriage return, line
// feed, non-breaking space, left-to-right mark, right-to-left mark
let various_spaces = " \t\u{b}\u{c}\r\n\u{a0}\u{200e}\u{200f}";
let tokens = various_spaces.parse::<TokenStream>().unwrap();
assert_eq!(tokens.into_iter().count(), 0);

let lone_carriage_return = " \r ";
lone_carriage_return.parse::<TokenStream>().unwrap_err();
}

#[test]
fn byte_order_mark() {
let string = "\u{feff}foo";
Expand Down