atifaziz / Hazz

CSS Selectors (via Fizzler) for HtmlAgilityPack (HAP)
Other
63 stars 7 forks source link

QuerySelectorAll() is case-sensitive for element name (tagName) #21

Closed gilad905 closed 3 years ago

gilad905 commented 3 years ago

Given a selector that includes an element name (i.e tagName), the method IEnumerable<HtmlNode> HtmlNode.QuerySelectorAll(string selector) will perform a case-sensitive search for the name.

In other words:

HtmlDocument document = new HtmlDocument(); document.LoadHtml("<html><body><a></a></body></html>"); document.DocumentNode.QuerySelectorAll("A"); // should select the <a> but will select nothing. document.DocumentNode.QuerySelectorAll("a"); // works fine.

W3C docs specify CSS selectors are not case-sensitive, except for specific attributes such as class or ID. This also how browsers' (at least my Chrome) querySelectorAll() will behave.

see also: https://stackoverflow.com/questions/7559205/are-css-selectors-case-sensitive/7559251

atifaziz commented 3 years ago

Also quoting the relevant section on case-sensitivity from the Selectors Level 3 specification is:

3. Case sensitivity

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].

So indeed, it should be case-insensitive for HTML and thank you for pointing this out.