- From: Tab Atkins Jr. via GitHub <sysbot+gh@w3.org>
- Date: Wed, 31 Jul 2024 23:52:52 +0000
- To: public-css-archive@w3.org
tabatkins has just created a new issue for https://github.com/w3c/csswg-drafts: == [cssom] "insert a CSS rule" should throw if given a valid rule *with* declarations == As currently specified, ["insert a CSS rule"](https://drafts.csswg.org/cssom/#insert-a-css-rule) invokes two parsing algos from Syntax: 1. First, it invokes ["parse a rule"](https://drafts.csswg.org/css-syntax-3/#parse-a-rule), which only succeeds if it finds exactly one valid rule in its input, and nothing else. 2. If that fails, it invokes ["parse a block's contents"](https://drafts.csswg.org/css-syntax-3/#parse-a-blocks-contents), and only pays attention to the declarations returned from the algo. (The algo returns a mixed list of rules and declaration lists.) If there are any valid declarations, it succeeds; otherwise it fails. This means that content like `@media (width: 100px) {...} --foo: bar;` will fail the first check (extra stuff after the rule), then successfully pass the second and append the `--foo: bar` as a CSSNestedDeclaration object, ignoring the completely valid `@media` rule that preceded it. (The algo also seems to be written against a slightly older version of the "parse a block's contents" algo, when it returned rules and declarations as separate lists. It's easy enough to parse what it means given the current return value, but it should probably be fixed.) I think this should be changed to look at the whole return value, and only succeed if it returned exactly one item that is a list of declarations. This means that (a) including valid rules mixed with declarations will fail, as I think we want, and (b) including *invalid* rules will even sometimes fail, if they show up between declarations. Like, `--one: 1; @invalid; --two: 2;` will produce two separate lists of declarations, each containing a single declaration. However, `@invalid; --one: 1;` won't trigger that, as it just returns a single list of declarations. We could even adjust the Syntax algo to return errors (or at least the presence of them), so the CSSOM algo can *consistently* fail when an invalid rule is used. Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10652 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Wednesday, 31 July 2024 23:52:53 UTC