Case Sensitivity of Attribute Names

Fell down a bit of a rabbit-hole this morning which looking into this bug report for Se-IDE. CSS Selectors that look at values are known and understood to be case sensitive; but what about the attribute name? That’s a bit more hairy.

To the specs!

From the Case Sensitivity section of the W3C Selectors Level 3 one:
All Selectors syntax is case-insensitive within the ASCII range (i.e. [a-z] and [A-Z] are equivalent), except for parts that are not under the control of Selectors. The case sensitivity of document language element names, attribute names, and attribute values in selectors depends on the document language. For example, in HTML, element names are case-insensitive, but in XML, they are case-sensitive. Case sensitivity of namespace prefixes is defined in [CSS3NAMESPACE].

A bit of a redirection here, but its a bread crumb. But requires some more spec reading.

First, from the Attributes section of the HTML 5 specification:
Attributes have a name and a value. Attribute names must consist of one or more characters other than the space characters, U+0000 NULL, U+0022 QUOTATION MARK (“), U+0027 APOSTROPHE (‘), U+003E GREATER-THAN SIGN (>), U+002F SOLIDUS (/), and U+003D EQUALS SIGN (=) characters, the control characters, and any characters that are not defined by Unicode. In the HTML syntax, attribute names, even those for foreign elements, may be written with any mix of lower- and uppercase letters that are an ASCII case-insensitive match for the attribute’s name.

And now from the Differences from HTML section of the XHTML specification:
XHTML documents must use lower case for all HTML element and attribute names. This difference is necessary because XML is case-sensitive e.g. <li> and <LI> are different tags.

The bug that started all this is saying that a CSS selector of a[onClick] was working but a[onclick]. My guess from all this is that the person who logged it is working against an XHTML page and not an HTML one. In that situation, the attributes are different, as would oNcLiCk, ONCLICK, onclicK and could all be included in a single element — even though technically it wouldn’t pass an XHTML validator (due to the mixed-case-ness). If it is HTML document, then all those variations are the same and could not be used at the same time in the same element. But individually they could and pass a validator.

I think I just broke my brain.

Trackbacks & Pingbacks 1

  1. From Confluence: Quality Assurance on 12 Aug 2011 at 1:46 am

    Reading Recommendations 12.08.2011…

    Reading Recommendations 12.08.2011 Critical This post & comic (!) by Andy Glover focus on the perception of the tester in a team. It’s easy to be seen as negative, so we should all remember to not only deliver bad, but also good news….

Post a Comment

Your email is never published nor shared. Required fields are marked *