Skip to content

Commit

Permalink
fix: make getSelector work with URIs that cannot be shortened
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanb committed Mar 8, 2018
1 parent a5ea385 commit a113555
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
17 changes: 11 additions & 6 deletions lib/core/utils/get-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ function getAttributeNameValue(node, at) {
let atnv;

if (name.indexOf('href') !== -1 || name.indexOf('src') !== -1) {
let value = encodeURI(axe.utils.getFriendlyUriEnd(node.getAttribute(name)));
if (value) {
atnv = escapeSelector(at.name) + '$="' + value + '"';
} else {
return;
}
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) + '"';
}
} else {
atnv = escapeSelector(name) + '="' + escapeSelector(at.value) + '"';
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@
"standard-version": "^4.2.0"
},
"dependencies": {}
}
}
10 changes: 10 additions & 0 deletions test/core/utils/get-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,16 @@ describe('axe.utils.getSelector', function () {
);
});

it('should work correctly when a URL attribute cannot be shortened', function () {
var href = 'mars2.html?a=be_bold';
var node = document.createElement('a');
node.setAttribute('href', href);
fixture.appendChild(node);
axe._tree = axe.utils.getFlattenedTree(document.documentElement);

assert.include(axe.utils.getSelector(node), href);
});

it('no options: should work with shadow DOM', function () {
var shadEl;

Expand Down

0 comments on commit a113555

Please sign in to comment.