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(html-lang-valid): only run rule when attribute has value #3663

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
2 changes: 1 addition & 1 deletion lib/rules/html-lang-valid.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "html-lang-valid",
"selector": "html[lang], html[xml\\:lang]",
"selector": "html[lang]:not([lang=\"\"]), html[xml\\:lang]:not([xml\\:lang=\"\"])",
"tags": ["cat.language", "wcag2a", "wcag311", "ACT"],
"actIds": ["bf051a"],
"metadata": {
Expand Down
2 changes: 2 additions & 0 deletions test/integration/full/html-lang-valid/frames/level1.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
<iframe id="frame3" src="level2-a.html"></iframe>
<iframe id="frame4" src="level2-b.html"></iframe>
<iframe id="frame5" src="level2-c.html"></iframe>
<iframe id="frame6" src="level2-d.html"></iframe>
<iframe id="frame7" src="level2-e.html"></iframe>
</body>
</html>
11 changes: 11 additions & 0 deletions test/integration/full/html-lang-valid/frames/level2-d.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html id="inapplicable2d" lang="">
<head>
<title>No lang test</title>
<meta charset="utf8" />
<script src="/axe.js"></script>
</head>
<body>
Empty lang
</body>
</html>
11 changes: 11 additions & 0 deletions test/integration/full/html-lang-valid/frames/level2-e.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html id="inapplicable2e" xml:lang="">
<head>
<title>No lang test</title>
<meta charset="utf8" />
<script src="/axe.js"></script>
</head>
<body>
Empty xml:lang
</body>
</html>
15 changes: 15 additions & 0 deletions test/integration/virtual-rules/html-lang-valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ describe('html-lang-valid virtual-rule', function () {
assert.lengthOf(results.incomplete, 0);
});

it('is inapplicable with empty lang or xml:lang', function () {
// Error caught by html-has-lang instead
var results = axe.runVirtualRule('html-lang-valid', {
nodeName: 'html',
attributes: {
lang: ''
}
});

assert.lengthOf(results.inapplicable, 1);
assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 0);
});

it('should pass with a valid lang', function () {
var results = axe.runVirtualRule('html-lang-valid', {
nodeName: 'html',
Expand Down