Files
firefox/testing/web-platform/tests/css/css-syntax/invalid-nested-rules.html
Anders Hartvoll Ruud 54c57107fe Bug 1920684 [wpt PR 48322] - [css-nesting] Keep parsing after {}-block for rules with invalid selector, a=testonly
Automatic update from web-platform-tests
[css-nesting] Keep parsing after {}-block for rules with invalid selector

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 <[email protected]>
Reviewed-by: Steinar H Gunderson <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1359288}

--

wpt-commits: 8ae822f00cd69c0c5a222e6e797391963dc22c78
wpt-pr: 48322
2024-09-25 07:31:52 +00:00

22 lines
726 B
HTML

<!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>