Skip to content

Commit

Permalink
fix(html-lang-valid): only run rule when attribute has value (#3663)
Browse files Browse the repository at this point in the history
* Change html-lang-valid selector so the rule only applies when attrs have a value. Fix #3624

* add integration tests

Co-authored-by: Steven Lambert <steven.lambert@deque.com>
  • Loading branch information
thibaudcolas and straker authored Nov 29, 2022
1 parent ac688c0 commit 1a7eecb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
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

0 comments on commit 1a7eecb

Please sign in to comment.