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

fix: Don't require all ARIA IDREFS to exist #921

Merged
merged 1 commit into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/commons/aria/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ aria.validateAttrValue = function (node, attr) {
return true;
}
list = axe.utils.tokenList(value);
// Check if any value isn't in the list of values
return list.reduce(function (result, token) {
return !!(result && doc.getElementById(token));
// Initial state, fail if the list is empty
}, list.length !== 0);
return list.some((token) => doc.getElementById(token));

case 'string':
// anything goes
Expand Down
11 changes: 8 additions & 3 deletions test/commons/aria/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,23 @@ describe('aria.validateAttrValue', function () {
});

it('should return false when a single referenced node is not found', function () {

node.setAttribute('cats', 'invalid');
// target2 not found
assert.isFalse(axe.commons.aria.validateAttrValue(node, 'cats'));
});

it('should return false when a referenced element is not found', function () {
it('should return false when at no referenced element is found', function () {
fixture.innerHTML = '<div id="target"></div>';
node.setAttribute('cats', 'target2 target3');
// target2 not found
assert.isFalse(axe.commons.aria.validateAttrValue(node, 'cats'));
});

it('should return true when at least one referenced element is found', function () {
fixture.innerHTML = '<div id="target"></div>';
node.setAttribute('cats', 'target target2');
// target2 not found
assert.isFalse(axe.commons.aria.validateAttrValue(node, 'cats'));
assert.isTrue(axe.commons.aria.validateAttrValue(node, 'cats'));
});

it('should return true when all targets are found', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h2>Possible False Positives</h2>
<div aria-controls=" ref ref2 " id="pass22">hi</div>

<div aria-describedby="ref" id="pass23">hi</div>
<div aria-describedby="ref ref2" id="pass24">hi</div>
<div aria-describedby="ref ref2 failref" id="pass24">hi</div>
<div aria-describedby=" ref ref2 " id="pass25">hi</div>

<div aria-disabled="true" id="pass26">hi</div>
Expand Down Expand Up @@ -117,7 +117,7 @@ <h2>Possible False Positives</h2>
<div aria-label="stuff" id="pass55">hi</div>

<div aria-labelledby="ref" id="pass56">hi</div>
<div aria-labelledby="ref ref2" id="pass57">hi</div>
<div aria-labelledby="ref ref2 failedref" id="pass57">hi</div>
<div aria-labelledby=" ref ref2 " id="pass58">hi</div>

<div aria-level="0" id="pass59">hi</div>
Expand Down Expand Up @@ -145,7 +145,7 @@ <h2>Possible False Positives</h2>
<div aria-orientation="vertical" id="pass76">hi</div>

<div aria-owns="ref" id="pass77">hi</div>
<div aria-owns="ref ref2" id="pass78">hi</div>
<div aria-owns="ref ref2 failedref" id="pass78">hi</div>
<div aria-owns=" ref ref2 " id="pass79">hi</div>

<div aria-posinset="0" id="pass80">hi</div>
Expand Down