diff --git a/lib/checks/label/alt-space-value.js b/lib/checks/label/alt-space-value.js new file mode 100644 index 0000000000..67fd2b6d66 --- /dev/null +++ b/lib/checks/label/alt-space-value.js @@ -0,0 +1,2 @@ +const validAttrValue = /^\s+$/.test(node.getAttribute('alt')); +return node.hasAttribute('alt') && validAttrValue; diff --git a/lib/checks/label/alt-space-value.json b/lib/checks/label/alt-space-value.json new file mode 100644 index 0000000000..11813fe00b --- /dev/null +++ b/lib/checks/label/alt-space-value.json @@ -0,0 +1,11 @@ +{ + "id": "alt-space-value", + "evaluate": "alt-space-value.js", + "metadata": { + "impact": "critical", + "messages": { + "pass": "Element has a valid alt attribute value", + "fail": "Element has an alt attribute containing only a space character, which is not ignored by all screen readers" + } + } +} diff --git a/lib/rules/image-alt.json b/lib/rules/image-alt.json index 6d688ee105..1b4791e31d 100644 --- a/lib/rules/image-alt.json +++ b/lib/rules/image-alt.json @@ -21,5 +21,5 @@ "role-presentation", "role-none" ], - "none": [] + "none": ["alt-space-value"] } diff --git a/lib/rules/landmark-complementary-is-top-level.json b/lib/rules/landmark-complementary-is-top-level.json index c06f1347e1..dac1e93e93 100644 --- a/lib/rules/landmark-complementary-is-top-level.json +++ b/lib/rules/landmark-complementary-is-top-level.json @@ -1,17 +1,12 @@ { - "id": "landmark-complementary-is-top-level", - "selector": "aside:not([role]), [role=complementary]", - "tags": [ - "cat.semantics", - "best-practice" - ], - "metadata": { - "description": "Ensures the complementary landmark or aside is at top level", - "help": "Aside must not be contained in another landmark" - }, - "all": [], - "any": [ - "landmark-is-top-level" - ], - "none": [] + "id": "landmark-complementary-is-top-level", + "selector": "aside:not([role]), [role=complementary]", + "tags": ["cat.semantics", "best-practice"], + "metadata": { + "description": "Ensures the complementary landmark or aside is at top level", + "help": "Aside must not be contained in another landmark" + }, + "all": [], + "any": ["landmark-is-top-level"], + "none": [] } diff --git a/test/checks/label/alt-space-value.js b/test/checks/label/alt-space-value.js new file mode 100644 index 0000000000..ff73233cb8 --- /dev/null +++ b/test/checks/label/alt-space-value.js @@ -0,0 +1,31 @@ +describe('alt-space-value', function() { + 'use strict'; + + var checkSetup = axe.testUtils.checkSetup; + var checkContext = axe.testUtils.MockCheckContext(); + var check = checks['alt-space-value']; + + afterEach(function() { + checkContext.reset(); + }); + + it('should return true if alt contains a space character', function() { + var params = checkSetup(' '); + assert.isTrue(check.evaluate.apply(checkContext, params)); + }); + + it('should return true if alt contains a non-breaking space character', function() { + var params = checkSetup(' '); + assert.isTrue(check.evaluate.apply(checkContext, params)); + }); + + it('should return false if alt attribute is empty', function() { + var params = checkSetup(''); + assert.isFalse(check.evaluate.apply(checkContext, params)); + }); + + it('should return false if alt attribute has a proper text value', function() { + var params = checkSetup('text content'); + assert.isFalse(check.evaluate.apply(checkContext, params)); + }); +}); diff --git a/test/integration/rules/image-alt/image-alt.html b/test/integration/rules/image-alt/image-alt.html index 14672b4b0d..3b49f6062f 100644 --- a/test/integration/rules/image-alt/image-alt.html +++ b/test/integration/rules/image-alt/image-alt.html @@ -15,5 +15,6 @@ + SVG Title diff --git a/test/integration/rules/image-alt/image-alt.json b/test/integration/rules/image-alt/image-alt.json index 088b528db5..8fe3368f91 100644 --- a/test/integration/rules/image-alt/image-alt.json +++ b/test/integration/rules/image-alt/image-alt.json @@ -7,7 +7,8 @@ ["#violation3"], ["#violation4"], ["#violation5"], - ["#violation6"] + ["#violation6"], + ["#violation7"] ], "passes": [ ["#pass1"],