Skip to content
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
Fix a panic in bad-url token parsing. Fix #174.
  • Loading branch information
SimonSapin committed Jul 25, 2017
commit bac23592a185225f4878fe82e02f742f9e45fdc0
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "cssparser"
version = "0.18.0"
version = "0.18.1"
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]

description = "Rust implementation of CSS Syntax Level 3"
Expand Down
8 changes: 8 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ fn outer_block_end_consumed() {
assert!(input.next().is_err());
}

/// https://github.com/servo/rust-cssparser/issues/174
#[test]
fn bad_url_slice_out_of_bounds() {
let mut input = ParserInput::new("url(\u{1}\\");
let mut parser = Parser::new(&mut input);
let _ = parser.next_including_whitespace_and_comments(); // This used to panic
}

#[test]
fn unquoted_url_escaping() {
let token = Token::UnquotedUrl("\
Expand Down
4 changes: 3 additions & 1 deletion src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,9 @@ fn consume_unquoted_url<'a>(tokenizer: &mut Tokenizer<'a>) -> Result<Token<'a>,
match_byte! { tokenizer.consume_byte(),
b')' => { break },
b'\\' => {
tokenizer.advance(1); // Skip an escaped ')' or '\'
if matches!(tokenizer.next_byte(), Some(b')') | Some(b'\\')) {
tokenizer.advance(1); // Skip an escaped ')' or '\'
}
}
_ => {},
}
Expand Down