-
Notifications
You must be signed in to change notification settings - Fork 792
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
fix(getSelector): Ensure nodename is eescaped #566
Conversation
Thanks @WilcoFiers! |
@rdeltour What's the the use case for that? When would the same system want to change the namespace, even though the element would be the same. I think it's a little clearer what element you're supposed to look at with the namespace specified, no? |
The use case is to make selectors match the element in an XHTML context, such as in EPUB. Let me try to clarify. This has to deal with whether the element has a namespace or not in the DOM, which depends on how the document was parsed (for instance, as XML or as HTML). Consider this example HTML document: <!doctype html>
<title>Example</title>
<meta charset="utf-8" />
<h1>Hi</h1>
<math xlink:href="#foo"></math>
<div xlink:href="#foo"></div>
<foo:bar></foo:bar> It's HTML, and parsed as such by a browser. On this document:
It's all in the rules defined by the HTML parsing algorithm. For instance, when the parser encounters an Now, consider this XHTML document: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:m="http://www.w3.org/1998/Math/MathML" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Example</title>
</head>
<body>
<h1>Hi</h1>
<m:math></m:math>
</body>
</html> If parsed as XHTML (for instance, put it in a file with the '.xhtml' extension and open it in a browser, or serve it with the
Again, the reason lies in the parsing algorithm. The MathML namespace is known and defined, so the local name is just "math" and the namespace is "http://www.w3.org/1998/Math/MathML". So, what should aXe do (ideally)? The easy approach would be to create A more correct approach would be to define the selector based on the value of Voilà. I hope it makes sense :-) |
Makes sense, and I learned something new today :D. Thanks Romain. @dylanb What do you think? Also, yes you can run specific tests by doing |
I think we should implement option 2 because it will only change selectors for XHTML documents which is less disruptive to our users |
Agreed. Any idea how to detect what parser was used on a page? I want to avoid changing the selectors as much as possible. If we can make it so that localName is used in xml documents, and nodeName in all other cases, that'd be ideal. Do you want to take a stab at updating this PR @rdeltour ? |
I think we can look at
Sure, I can try in the coming days (end of next week at the latest). |
- by default, ensure the nodename is escaped - for XHTML documents, only use the local name Replaces dequelabs#566 Closes dequelabs#563
I saw a real-world case of invalid/namespaced HTML tags rendered from the server today, and they took down axe-core and our extensions. Here's an example:
I have a question out as to whether this was an XHTML or HTML5 doctype, but I'd be curious to see if namespaced HTML tags in a regular document like this cause any problems for assistive technologies. If they do cause problems, it might be a good thing for axe-core to flag. |
Good question. To be honest I have no idea, but I suspect most ATs would just ignore it (as HTML parsers do). |
PR superseded by #582 |
- by default, ensure the nodename is escaped - for XHTML documents, only use the local name Replaces dequelabs#566 Closes dequelabs#563
- by default, ensure the nodename is escaped - for XHTML documents, only use the local name Replaces dequelabs#566 Closes dequelabs#563
) * feat(utils): add function `isXHTML` to test if a document node is XHTML * test(utils): add a test for `axe.utils.isXHTML` on an XHTML document * fix(getSelector): improve selectors for namespaced elements - by default, ensure the nodename is escaped - for XHTML documents, only use the local name Replaces #566 Closes #563 * test(getSelector): add a test for `axe.utils.getSelector` on a namespaced XHTML element
) * feat(utils): add function `isXHTML` to test if a document node is XHTML * test(utils): add a test for `axe.utils.isXHTML` on an XHTML document * fix(getSelector): improve selectors for namespaced elements - by default, ensure the nodename is escaped - for XHTML documents, only use the local name Replaces #566 Closes #563 * test(getSelector): add a test for `axe.utils.getSelector` on a namespaced XHTML element
Co-authored-by: Steven Lambert <[email protected]>
Closes #563