Skip to content

Commit

Permalink
fix: Don't require all ARIA IDREFS to exist (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored May 30, 2018
1 parent a8e801c commit 130efed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
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

0 comments on commit 130efed

Please sign in to comment.