Skip to content

Commit

Permalink
[css-nesting] Keep parsing after {}-block for rules with invalid sele…
Browse files Browse the repository at this point in the history
…ctor

When encountering a rule with an invalid selector, we currently recover
by consuming until the next semicolon, which isn't correct. Instead,
we should simply do nothing, and keep parsing right after the {}-block.

The spec used to be less clear about this, but at least at the time
of writing, nothing invokes the skip-until-semicolon behavior except
for rule preludes that look like custom properties.

This CL fixes this issue by adding a `invalid_rule_error` out-param
to ConsumeStyleRule. There are two other things that are worth noting:

 - The "consume a qualified rule" algorithm in the spec mentions
   a `nested` flag which modifies its behavior. This flag is
   actually equivalent to `semicolon_aborts_nested_selector`
   in our parser, so I've renamed this.
 - During handling of `custom_property_ambiguity`, nested=false case,
   we're supposed to consume a block, and do nothing.
   This can't be tested using CSSParserImpl's public API, since
   failing to consume a block there would just cause the next attempt
   at parsing a rule to consume an empty prelude (then the block).
   But I don't think we should rely on that, hence I'm using unit
   tests to cover that line.

[1] https://drafts.csswg.org/css-syntax/#consume-qualified-rule

Test: external/wpt/css/css-syntax/custom-property-rule-ambiguity.html
Change-Id: I04dc0c3745be5eafe792fd6c40971545274d9794
Fixed: 343979378
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5881815
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Steinar H Gunderson <sesse@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1359288}
  • Loading branch information
andruud authored and chromium-wpt-export-bot committed Sep 24, 2024
1 parent 266b949 commit 8ae822f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions css/css-syntax/invalid-nested-rules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<title>CSS Syntax: invalid rule errors when nested</title>
<link rel="help" href="https://drafts.csswg.org/css-syntax/#invalid-rule-error">
<link rel="help" href="https://drafts.csswg.org/css-syntax/#consume-qualified-rule">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style id=style>
.a {
.b <::::invalid::::> {}
& .c {}
}
</style>
<script>
test(() => {
let rules = style.sheet.rules;
assert_equals(rules.length, 1);
let childRules = rules[0].cssRules;
assert_equals(childRules.length, 1);
assert_equals(childRules[0].selectorText, '& .c');
}, 'Continues parsing after block on invalid rule error');
</script>

0 comments on commit 8ae822f

Please sign in to comment.