[csswg-drafts] [mediaqueries-5] Parsing `<media-query-list>` when the input is `<whitespace-token>` (#9173)

cdoublev has just created a new issue for https://github.com/w3c/csswg-drafts:

== [mediaqueries-5] Parsing `<media-query-list>` when the input is `<whitespace-token>` ==
This is a follow-up of #7040, which reports an issue when parsing a whitespace against `<media-query-list>`.

If I am not mistaken, in `@media {}`, the input would be the `<whitespace-token>` between `@media` and `{}`.

  > To parse a `<media-query-list>` production, [parse a comma-separated list of component values](https://drafts.csswg.org/css-syntax-3/#parse-a-comma-separated-list-of-component-values), then parse each entry in the returned list as a `<media-query>`. Its value is the list of `<media-query>`s so produced.

https://drafts.csswg.org/mediaqueries-5/#typedef-media-query-list

  > 1. Normalize `input`, and set input to the result.
  > 2. Let `groups` be an empty list.
  > 3. While `input` is not empty: [...]
  >   1. Consume a list of component values from `input`, with `<comma-token>` as the stop token, and append the result to `groups`.
  >   2. Discard a token from input.
  > 4. Return `groups`.

https://drafts.csswg.org/css-syntax-3/#parse-a-comma-separated-list-of-component-values

If I am not mistaken, `groups` contains `<whitespace-token>` as its unique item, which is parsed against `<media-query>`, which returns an invalid result.

  > A media query that does not match the grammar in the previous section must be replaced by not all during parsing.

https://drafts.csswg.org/mediaqueries-5/#error-handling

If I am not mistaken, the invalid result in `groups` is replaced by `not all`.

In Chrome/FF:

```html
<style>
  @media {} /* Evaluates to true */
</style>
<script>
  document.styleSheets[0].cssRules[0].cssText// @media  {\n}
</script>
```

Indeed, their behavior conforms to the spec:

  > Note: This definition of `<media-query-list>` parsing intentionally accepts an empty list.

  > An empty media query list evaluates to true.

---

Before [this resolution](https://github.com/w3c/csswg-drafts/issues/7595#issuecomment-1284268421) to preserve invalid media queries, I would have suggested to parse `<media-query-list>` with [*parse a comma-separated list according to a CSS grammar*](https://drafts.csswg.org/css-syntax-3/#css-parse-a-comma-separated-list-according-to-a-css-grammar), which handle whitespaces by returning an empty list. But it also replaces comma-separated values by the result from their parse against the given grammar (`<media-query>`): invalid media queries are lost at this step.

I also feel like whitespaces between an at-rule name and its prelude should be consumed in *consume an at-rule* (like whitespaces between a declaration name and value), and that the prelude of `@media` should be defined with `<media-query-list>?`.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9173 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 9 August 2023 07:49:02 UTC