From 8ae822f00cd69c0c5a222e6e797391963dc22c78 Mon Sep 17 00:00:00 2001 From: Anders Hartvoll Ruud Date: Tue, 24 Sep 2024 05:02:19 -0700 Subject: [PATCH] [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 Reviewed-by: Steinar H Gunderson Cr-Commit-Position: refs/heads/main@{#1359288} --- css/css-syntax/invalid-nested-rules.html | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 css/css-syntax/invalid-nested-rules.html diff --git a/css/css-syntax/invalid-nested-rules.html b/css/css-syntax/invalid-nested-rules.html new file mode 100644 index 00000000000000..a277305496eeaa --- /dev/null +++ b/css/css-syntax/invalid-nested-rules.html @@ -0,0 +1,21 @@ + +CSS Syntax: invalid rule errors when nested + + + + + +