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

DOMException: Failed to execute 'matches' on 'Element' #1137

Closed
stephenmathieson opened this issue Sep 13, 2018 · 2 comments
Closed

DOMException: Failed to execute 'matches' on 'Element' #1137

stephenmathieson opened this issue Sep 13, 2018 · 2 comments
Labels
core Issues in the core code (lib/core) fix Bug fixes

Comments

@stephenmathieson
Copy link
Member

Attempting to run axe-core on https://eclkc.ohs.acf.hhs.gov/education-child-development yields the following error:

VM60:3472 Uncaught (in promise) DOMException: Failed to execute 'matches' on 'Element': 'a[href="  /child-screening-assessment
"] > .card__image > .card__text' is not a valid selector.
    at Object.matchesSelector (<anonymous>:3472:26)
    at <anonymous>:4002:28
    at Array.filter (<anonymous>)
    at generateSelector (<anonymous>:4001:27)
    at Object.createUniqueSelector [as getSelector] (<anonymous>:4038:14)
    at DqElement.get selector [as selector] (<anonymous>:3429:48)
    at <anonymous>:2399:51
    at Array.map (<anonymous>)
    at <anonymous>:2392:47
    at Array.map (<anonymous>)

It looks like this page contains newlines in attribute values, which causes axe-core to produce invalid selectors. Example (note the href):

<a href="  /child-screening-assessment
  " class="no-icon" rel="bookmark">
    [...]
</a>

This error occurs with axe-core versions 3.0.3 and 3.1.1, but 2.5.0 is fine.

@WilcoFiers WilcoFiers added the fix Bug fixes label Sep 18, 2018
@WilcoFiers WilcoFiers added the core Issues in the core code (lib/core) label Oct 18, 2018
@straker
Copy link
Contributor

straker commented Feb 13, 2019

The bug is in the axe.utils.getSelector code where the only thing we don't escape is the href attribute.

if (name.indexOf('href') !== -1 || name.indexOf('src') !== -1) {
let friendly = axe.utils.getFriendlyUriEnd(node.getAttribute(name));
if (friendly) {
let value = encodeURI(friendly);
if (value) {
atnv = escapeSelector(at.name) + '$="' + value + '"';
} else {
return;
}
} else {
atnv = escapeSelector(at.name) + '="' + node.getAttribute(name) + '"';
}

@stephenmathieson
Copy link
Member Author

Nice find, Steven!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues in the core code (lib/core) fix Bug fixes
Projects
None yet
Development

No branches or pull requests

3 participants