From eb04e603952512106e7a41fc49bbd31aafd273f6 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Sat, 17 Sep 2022 16:29:13 +0100 Subject: [PATCH] Change html-lang-valid selector so the rule only applies when attrs have a value. Fix #3624 --- lib/rules/html-lang-valid.json | 2 +- test/integration/virtual-rules/html-lang-valid.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/rules/html-lang-valid.json b/lib/rules/html-lang-valid.json index 19fd4c01c9..5cf81f4325 100644 --- a/lib/rules/html-lang-valid.json +++ b/lib/rules/html-lang-valid.json @@ -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": { diff --git a/test/integration/virtual-rules/html-lang-valid.js b/test/integration/virtual-rules/html-lang-valid.js index d89d410ca6..8e7675a7a2 100644 --- a/test/integration/virtual-rules/html-lang-valid.js +++ b/test/integration/virtual-rules/html-lang-valid.js @@ -6,6 +6,21 @@ describe('html-lang-valid virtual-rule', function() { attributes: {} }); + assert.lengthOf(results.inapplicable, 1); + assert.lengthOf(results.passes, 0); + assert.lengthOf(results.violations, 0); + 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);