-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rule): Ignore hashbang URLs for skiplinks (#827)
- Loading branch information
1 parent
5651ecc
commit e1f0c57
Showing
5 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
const links = axe.utils.querySelectorAll(virtualNode, 'a[href]'); | ||
return links.some(vLink => vLink.actualNode.getAttribute('href')[0] === '#'); | ||
return links.some(vLink => { | ||
return /^#[^/!]/.test(vLink.actualNode.getAttribute('href')) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
const href = node.getAttribute('href'); | ||
return (href[0] === '#' && href.length > 1); | ||
return /^#[^/!]/.test(node.getAttribute('href')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
describe('skip-link-matches', function () { | ||
'use strict'; | ||
|
||
var rule, link; | ||
var fixture = document.getElementById('fixture'); | ||
|
||
beforeEach(function () { | ||
rule = axe._audit.rules.find(function (rule) { | ||
return rule.id === 'skip-link'; | ||
}); | ||
link = document.createElement('a') | ||
}); | ||
|
||
afterEach(function () { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('is a function', function () { | ||
assert.isFunction(rule.matches); | ||
}); | ||
|
||
it('returns false if the href attribute does not start with #', function () { | ||
link.href = 'foo#bar'; | ||
assert.isFalse(rule.matches(link)); | ||
}); | ||
|
||
it('returns false if the href attribute is `#`', function () { | ||
link.href = '#'; | ||
assert.isFalse(rule.matches(link)); | ||
}); | ||
|
||
it('returns true if the href attribute starts with #', function () { | ||
link.href = '#foo'; | ||
assert.isTrue(rule.matches(link)); | ||
}); | ||
|
||
it('returns false if the href attribute starts with #!', function () { | ||
link.href = '#!foo'; | ||
assert.isFalse(rule.matches(link)); | ||
}); | ||
|
||
it('returns false if the href attribute starts with #/', function () { | ||
link.href = '#/foo'; | ||
assert.isFalse(rule.matches(link)); | ||
}); | ||
}); |