Skip to content

Commit

Permalink
fix(rule): skip-link rule doesn't decode URI encoded href's
Browse files Browse the repository at this point in the history
If href contains url encoded fragment like "<a href="#%3Ctarget%3E">Click Here</a>" it leads to false positive violation due to no target
  • Loading branch information
skydreamerr authored and Andrey Nazarov committed Mar 12, 2018
1 parent 22607b6 commit 818b5cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/commons/dom/get-element-by-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dom.getElementByReference = function (node, attr) {
let fragment = node.getAttribute(attr);

if (fragment && fragment.charAt(0) === '#') {
fragment = fragment.substring(1);
fragment = decodeURIComponent(fragment.substring(1));

let candidate = document.getElementById(fragment);
if (candidate) {
Expand Down
6 changes: 6 additions & 0 deletions test/checks/navigation/skip-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ describe('skip-link', function () {
var node = fixture.querySelector('a');
assert.isUndefined(checks['skip-link'].evaluate(node));
});

it('should return true if the URI encoded href points to an element with an ID', function () {
fixture.innerHTML = '<a href="#%3Ctarget%3E">Click Here</a><h1 id="&lt;target&gt;">Introduction</h1>';
var node = fixture.querySelector('a');
assert.isTrue(checks['skip-link'].evaluate(node));
});
});

0 comments on commit 818b5cd

Please sign in to comment.