Skip to content

Commit acac1ce

Browse files
author
bors-servo
authored
Auto merge of #185 - servo:…, r=emilio
Fix interaction of skip_whitespace and nested blocks This fixes (at least some of) the test failures at servo/servo#18171 In code like this: ```css unsupported selector ! { stuff } valid selector { color: green } ``` `rules_and_declarations::parse_qualified_rule` would leave the parser just after the first `{` with `Parser::at_start_of == Some(BlockType::CurlyBracket)`. The latter means that, unless `Parser::parse_nested_block` is called, the parser needs to skip over this block until the matching `}` before doing anything else. This PR makes `Parser::skip_whitespace` and `Parser::skip_cdc_and_cdo` (both added recently in #181) take care of `Parser::at_start_of` correctly the same way `Parser::next` does. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/185) <!-- Reviewable:end -->
2 parents a161e1f + 0acff3b commit acac1ce

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/parser.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,19 @@ impl<'i: 't, 't> Parser<'i, 't> {
300300
/// Advance the input until the next token that’s not whitespace or a comment.
301301
#[inline]
302302
pub fn skip_whitespace(&mut self) {
303-
// If we just consumed `{`, `[`, `(`, or `function(`, leave whitespace
304-
// or comments inside the block or function up to the nested parser.
305-
if self.at_start_of.is_some() {
306-
return
303+
if let Some(block_type) = self.at_start_of.take() {
304+
consume_until_end_of_block(block_type, &mut self.input.tokenizer);
307305
}
308306

309307
self.input.tokenizer.skip_whitespace()
310308
}
311309

312310
#[inline]
313311
pub(crate) fn skip_cdc_and_cdo(&mut self) {
312+
if let Some(block_type) = self.at_start_of.take() {
313+
consume_until_end_of_block(block_type, &mut self.input.tokenizer);
314+
}
315+
314316
self.input.tokenizer.skip_cdc_and_cdo()
315317
}
316318

0 commit comments

Comments
 (0)