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(valid-attr-value): Return incomplete when aria-describedby reference a missing element #1671

Merged
merged 1 commit into from
Jul 8, 2019
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
24 changes: 21 additions & 3 deletions lib/checks/aria/valid-attr-value.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
options = Array.isArray(options) ? options : [];

const needsReview = [];
const invalid = [];
const aria = /^aria-/;
const attrs = axe.utils.getNodeAttributes(node);

const skipAttrs = ['aria-errormessage'];

// aria-controls should only check if element exists if the element
// doesn't have aria-expanded=false or aria-selected=false (tabs)
// @see https://github.com/dequelabs/axe-core/issues/1463
const preChecks = {
// aria-controls should only check if element exists if the element
// doesn't have aria-expanded=false or aria-selected=false (tabs)
// @see https://github.com/dequelabs/axe-core/issues/1463
'aria-controls': function() {
return (
node.getAttribute('aria-expanded') !== 'false' &&
Expand All @@ -21,6 +22,18 @@ const preChecks = {
// @see https://github.com/dequelabs/axe-core/issues/1524
'aria-owns': function() {
return node.getAttribute('aria-expanded') !== 'false';
},
// aria-describedby should not mark missing element as violation but
// instead as needs review
// @see https://github.com/dequelabs/axe-core/issues/1151
'aria-describedby': function() {
if (!axe.commons.aria.validateAttrValue(node, 'aria-describedby')) {
needsReview.push(
`aria-describedby="${node.getAttribute('aria-describedby')}"`
);
}

return;
}
};

Expand All @@ -39,6 +52,11 @@ for (let i = 0, l = attrs.length; i < l; i++) {
}
}

if (needsReview.length) {
this.data(needsReview);
return undefined;
}

if (invalid.length) {
this.data(invalid);
return false;
Expand Down
3 changes: 2 additions & 1 deletion lib/checks/aria/valid-attr-value.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"impact": "critical",
"messages": {
"pass": "ARIA attribute values are valid",
"fail": "Invalid ARIA attribute value{{=it.data && it.data.length > 1 ? 's' : ''}}:{{~it.data:value}} {{=value}}{{~}}"
"fail": "Invalid ARIA attribute value{{=it.data && it.data.length > 1 ? 's' : ''}}:{{~it.data:value}} {{=value}}{{~}}",
"incomplete": "ARIA attribute{=it.data && it.data.length > 1 ? 's' : ''}} element ID does not exist on the page:{{~it.data:value}} {{=value}}{{~}}"
}
}
}
8 changes: 8 additions & 0 deletions test/checks/aria/valid-attr-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ describe('aria-valid-attr-value', function() {
);
});

it('should return undefined on aria-describedby when the element is not in the DOM', function() {
fixtureSetup('<button aria-describedby="test">Button</button>');
var undefined1 = fixture.querySelector('button');
assert.isUndefined(
checks['aria-valid-attr-value'].evaluate.call(checkContext, undefined1)
);
});

describe('options', function() {
it('should exclude supplied attributes', function() {
fixture.innerHTML =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ <h2>Violations</h2>
<div aria-checked="stuff" id="violation6">hi</div>
<div aria-controls="stuff" id="violation7">hi</div>
<div aria-current="stage" id="violation8">hi</div>
<div aria-describedby="stuff" id="violation9">hi</div>
<div aria-disabled="stuff" id="violation10">hi</div>
<div aria-dropeffect="stuff" id="violation11">hi</div>
<div aria-expanded="stuff" id="violation12">hi</div>
Expand Down Expand Up @@ -269,4 +268,6 @@ <h2>Possible False Positives</h2>

<div id="ref">Hi</div>
<div id="ref2">Hi2</div>

<div aria-describedby="stuff" id="incomplete1">hi</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
["#violation6"],
["#violation7"],
["#violation8"],
["#violation9"],
["#violation10"],
["#violation11"],
["#violation12"],
Expand Down Expand Up @@ -224,5 +223,6 @@
["#pass182"],
["#pass183"],
["#pass184"]
]
],
"incomplete": [["#incomplete1"]]
}