[csswg-drafts] [selectors-4] [css-syntax-3] Does the U+0000 → U+FFFD rule apply to selector parsing? (#4927)

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

== [selectors-4] [css-syntax-3] Does the U+0000 → U+FFFD rule apply to selector parsing? ==
I just added a test at http://wpt.live/dom/nodes/ParentNode-querySelector-escapes.html which boils down to

```js
const el = document.createElement("span");
el.id = "\u{fffd}";
document.body.append(el);

assert_equals(document.body.querySelector("#\u{0}"), el);
```

i.e. which assumes the selector `"#\u{0}"` gets parsed as `"#\u{fffd}"`. (Note: this is distinct from the selector represented in JS code as `"\\u000"`; we are using JS escapes, not CSS escapes, so the string contains a literal U+0000 code point, not a backslash, u, etc.)

Firefox passes this past, while Chrome and Safari fail it.

However I'm unsure if the spec actually implies this. [Parse a selector](https://drafts.csswg.org/selectors-4/#parse-selector) links to [`<selector-list>`](https://drafts.csswg.org/selectors-4/#typedef-selector-list) which bottoms out in [`<hash-token>`](https://drafts.csswg.org/css-syntax-3/#typedef-hash-token). Nothing there explicitly handles U+0000, and it has an inclusive-sounding sentence "value composed of zero or more code points".

The [tokenization section](https://drafts.csswg.org/css-syntax-3/#input-preprocessing) of css-syntax-3 makes a U+0000 → U+FFFD replacement. However, it's not clear to me whether this applies to selector parsing when the selectors enter via DOM APis and the "parse a selector" algorithm. My best guess is that it applies to CSS style sheets only.

If the intention is to apply the tokenization rules to selector parsing, I'd suggest linking the word parse in step 1 of [parse a selector](https://drafts.csswg.org/selectors-4/#parse-selector) (and [parse a relative selector](https://drafts.csswg.org/selectors-4/#parse-relative-selector)) to some algorithm which feeds a string as the input stream into the tokenizer, then into the grammar. If the intention is to apply the tokenization rules only to CSS style sheets, then maybe a note in that section would be better.

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

Received on Tuesday, 7 April 2020 15:30:06 UTC