Skip to content

Commit 2cfe870

Browse files
committed
Fix servo#71: parsing bug when nesting blocks of the same kind
… and not consuming the inner block.
1 parent 8bf3326 commit 2cfe870

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/parser.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ impl<'i, 't> Parser<'i, 't> {
373373
stop_before: closing_delimiter,
374374
};
375375
result = nested_parser.parse_entirely(parse);
376+
if let Some(block_type) = nested_parser.at_start_of {
377+
consume_until_end_of_block(block_type, &mut *nested_parser.tokenizer);
378+
}
376379
}
377380
consume_until_end_of_block(block_type, &mut *self.tokenizer);
378381
result

src/tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,17 @@ fn expect_no_error_token() {
280280
}
281281

282282

283+
/// https://github.com/servo/rust-cssparser/issues/71
284+
#[test]
285+
fn outer_block_end_consumed() {
286+
let mut input = Parser::new("(calc(true))");
287+
assert!(input.expect_parenthesis_block().is_ok());
288+
assert!(input.parse_nested_block(|input| input.expect_function_matching("calc")).is_ok());
289+
println!("{:?}", input.position());
290+
assert_eq!(input.next(), Err(()));
291+
}
292+
293+
283294
fn run_color_tests<F: Fn(Result<Color, ()>) -> Json>(json_data: &str, to_json: F) {
284295
run_json_tests(json_data, |input| {
285296
to_json(input.parse_entirely(Color::parse))

0 commit comments

Comments
 (0)