Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case sensitivity of namespaced attributes of HTML elements in HTML documents #2694

Closed
SimonSapin opened this issue May 17, 2017 · 8 comments
Closed
Labels
interop Implementations are not interoperable with each other normative change

Comments

@SimonSapin
Copy link
Contributor

https://html.spec.whatwg.org/multipage/scripting.html#selectors

When comparing the name part of a CSS attribute selector to the names of namespace-less attributes on HTML elements in HTML documents, the name part of the CSS attribute selector must first be converted to ASCII lowercase. The same selector when compared to other attributes must be compared according to its original case. In both cases, the comparison is case-sensitive.

(Emphasis added.)

Test case: https://jsfiddle.net/zbcoys5x/

<style>
  [*|FOO="bar"] { color: red; }
</style>
<div>text</div>
<script>
  document.querySelector("div").setAttributeNS("x", "foo", "bar");
</script>

In Firefox, Chrome, and Safari, the text is red. The lower-case name appears to be used for all attributes, not only namespace-less ones. Edge shows the test black, it appears to follow the spec on that point.

Note that the parser never produces an attribute where this makes a difference. Using setAttributeNS is required to create a namespaced attribute on an HTML element in an HTML document.

I’d like the spec to be changed to align with three implementations against one by removing “namespace-less” in the paragraph quoted above:

When comparing the name part of a CSS attribute selector to the names of attributes on HTML elements in HTML documents, […]

CC @bzbarsky

@domenic domenic added interop Implementations are not interoperable with each other normative change labels May 17, 2017
@domenic
Copy link
Member

domenic commented May 17, 2017

Sounds very reasonable to me. Would you be up for writing a pull request and/or web platform tests?

@annevk
Copy link
Member

annevk commented May 17, 2017

So you cannot match attributes with a name in uppercase?

This requirement also makes it harder to reuse a parsed stylesheet across HTML and XML documents. I wonder if there's not a better solution.

@SimonSapin
Copy link
Contributor Author

@annevk With the current spec text, you cannot match namespace-less attributes with a name in uppercase in HTML elements in HTML documents (which are also never produced by the parser). With my proposed change, that would be the case regardless of namespace. But still only on HTML elements in HTML documents.

I don’t understand your point about sharing stylesheets. The "in HTML documents" bit is about the element being matched, not about the stylesheet.

SimonSapin added a commit to web-platform-tests/wpt that referenced this issue May 20, 2017
On elements in the HTML namespace in HTML documents,
selector matching of attribute names is ASCII-case insensitive
regardless of the attribute’s namespace.

This is a change proposed in whatwg/html#2694.
In the HTML spec before that change, this case-insensitivity only
applies to namespace-less attributes.

(Note that the HTML parser never crates namespaced attributes
on HTML elements, so using the DOM’s `setAttributeNS` is necessary
to create a situation where this change is observable.)

This change matches Firefox 53 and Chromium 58:
the number of passing/failing sub-tests didn’t change.
SimonSapin added a commit to SimonSapin/html that referenced this issue May 20, 2017
@SimonSapin
Copy link
Contributor Author

While editing I noticed that the previous section has very similar text:

https://html.spec.whatwg.org/multipage/scripting.html#case-sensitivity-of-the-css-%27attr()%27-function

When comparing the attribute name part of a CSS 'attr()' function to the names of namespace-less attributes on HTML elements in HTML documents, the name part of the CSS 'attr()' function must first be converted to ASCII lowercase. The same function when compared to other attributes must be compared according to its original case. In both cases, the comparison is case-sensitive.

It may make sense to make a similar change here for consistency, though this case is less annoying to implement since (unlike attribute selectors) attr() does not support *|foo namespace wildcards, so case-sensitivity is decidable before attribute lookup.

SimonSapin added a commit to web-platform-tests/wpt that referenced this issue May 20, 2017
On elements in the HTML namespace in HTML documents,
selector matching of attribute names is ASCII-case insensitive
regardless of the attribute’s namespace.

This is a change proposed in whatwg/html#2694.
In the HTML spec before that change, this case-insensitivity only
applies to namespace-less attributes.

(Note that the HTML parser never crates namespaced attributes
on HTML elements, so using the DOM’s `setAttributeNS` is necessary
to create a situation where this change is observable.)

This change matches Firefox 53 and Chromium 58:
the number of passing/failing sub-tests didn’t change.
@annevk
Copy link
Member

annevk commented May 22, 2017

@SimonSapin what are the chances of Selectors just defining this inline just like CSS defines how the HTML body element is special when it comes to overflow and such?

It still seems somewhat problematic from a theoretical angle, as this precludes the addition of a namespaced attribute with an uppercase letter from being used in HTML. It's unlikely we ever wanted to make such an addition, but I doubt that if someone in the future ever did make that decision, they'd realize it would break Selectors. Whereas not introducing namespace-less attributes with uppercase letters is how HTML already works.

@SimonSapin
Copy link
Contributor Author

@annevk Are you proposing moving the whole “4.16 Matching HTML elements using selectors and CSS” section into the Selectors spec? I don’t have an opinion on that, you’d need to propose it to the editors of that spec and CSSWG.

@zcorpan
Copy link
Member

zcorpan commented May 23, 2017

Is there a performance or implementation complexity reason to prefer any namespace?

@SimonSapin
Copy link
Contributor Author

Implementation complexity, yes. In particular for the namespace-wildcard case: when matching [*|Foo] in the current spec, you need to iterate all attributes, look if a given attribute has a namespace, and based on that decide to use the original or lower-cased name in the selector to compare against the content attribute’s local name. In every other case, or with the proposed change in every case, you can decide which of the original or lower-cased name to pick before doing attribute lookup.

(For what it’s worth, Servo and Stylo share a selector matching library that can be used with different content tree data structures, so there is an abstraction boundary there.)

zcorpan pushed a commit to web-platform-tests/wpt that referenced this issue Jun 5, 2017
On elements in the HTML namespace in HTML documents,
selector matching of attribute names is ASCII-case insensitive
regardless of the attribute’s namespace.

This is a change proposed in whatwg/html#2694.
In the HTML spec before that change, this case-insensitivity only
applies to namespace-less attributes.

(Note that the HTML parser never crates namespaced attributes
on HTML elements, so using the DOM’s `setAttributeNS` is necessary
to create a situation where this change is observable.)

This change matches Firefox 53 and Chromium 58:
the number of passing/failing sub-tests didn’t change.
@zcorpan zcorpan closed this as completed in 822a911 Jun 5, 2017
alice pushed a commit to alice/html that referenced this issue Jan 8, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interop Implementations are not interoperable with each other normative change
Development

No branches or pull requests

4 participants