Skip to content

Commit 130efed

Browse files
authored
fix: Don't require all ARIA IDREFS to exist (#921)
1 parent a8e801c commit 130efed

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

lib/commons/aria/attributes.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ aria.validateAttrValue = function (node, attr) {
8989
return true;
9090
}
9191
list = axe.utils.tokenList(value);
92-
// Check if any value isn't in the list of values
93-
return list.reduce(function (result, token) {
94-
return !!(result && doc.getElementById(token));
95-
// Initial state, fail if the list is empty
96-
}, list.length !== 0);
92+
return list.some((token) => doc.getElementById(token));
9793

9894
case 'string':
9995
// anything goes

test/commons/aria/attributes.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,23 @@ describe('aria.validateAttrValue', function () {
239239
});
240240

241241
it('should return false when a single referenced node is not found', function () {
242-
243242
node.setAttribute('cats', 'invalid');
244243
// target2 not found
245244
assert.isFalse(axe.commons.aria.validateAttrValue(node, 'cats'));
246245
});
247246

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

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

256261
it('should return true when all targets are found', function () {

test/integration/rules/aria-valid-attr-value/aria-valid-attr-value.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ <h2>Possible False Positives</h2>
7474
<div aria-controls=" ref ref2 " id="pass22">hi</div>
7575

7676
<div aria-describedby="ref" id="pass23">hi</div>
77-
<div aria-describedby="ref ref2" id="pass24">hi</div>
77+
<div aria-describedby="ref ref2 failref" id="pass24">hi</div>
7878
<div aria-describedby=" ref ref2 " id="pass25">hi</div>
7979

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

119119
<div aria-labelledby="ref" id="pass56">hi</div>
120-
<div aria-labelledby="ref ref2" id="pass57">hi</div>
120+
<div aria-labelledby="ref ref2 failedref" id="pass57">hi</div>
121121
<div aria-labelledby=" ref ref2 " id="pass58">hi</div>
122122

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

147147
<div aria-owns="ref" id="pass77">hi</div>
148-
<div aria-owns="ref ref2" id="pass78">hi</div>
148+
<div aria-owns="ref ref2 failedref" id="pass78">hi</div>
149149
<div aria-owns=" ref ref2 " id="pass79">hi</div>
150150

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

0 commit comments

Comments
 (0)