From ba89c29b988740f36ceefbf7631d03882018e70c Mon Sep 17 00:00:00 2001 From: Doga Genc Date: Sun, 3 May 2020 23:28:53 +0300 Subject: [PATCH] fix img-reduntant-alt bug (#4771) --- src/compiler/compile/nodes/Element.ts | 6 +++--- test/validator/samples/a11y-img-redundant-alt/input.svelte | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 93997ae66e..5cda9919af 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -438,7 +438,7 @@ export default class Element extends Node { if (href_attribute) { const href_value = href_attribute.get_static_value(); - + if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) { component.warn(href_attribute, { code: `a11y-invalid-attribute`, @@ -484,11 +484,11 @@ export default class Element extends Node { const aria_hidden_attribute = attribute_map.get('aria-hidden'); const aria_hidden_exist = aria_hidden_attribute && aria_hidden_attribute.get_static_value(); - + if (alt_attribute && !aria_hidden_exist) { const alt_value = alt_attribute.get_static_value(); - if (alt_value.match(/\b(image|picture|photo)\b/i)) { + if (alt_value && alt_value.match(/\b(image|picture|photo)\b/i)) { component.warn(this, { code: `a11y-img-redundant-alt`, message: `A11y: Screenreaders already announce elements as an image.` diff --git a/test/validator/samples/a11y-img-redundant-alt/input.svelte b/test/validator/samples/a11y-img-redundant-alt/input.svelte index 3ba029844d..cd942ce2a0 100644 --- a/test/validator/samples/a11y-img-redundant-alt/input.svelte +++ b/test/validator/samples/a11y-img-redundant-alt/input.svelte @@ -4,4 +4,5 @@ Image of me at a bar! Picture of baz fixing a bug. Plant doing photosynthesis in the afternoon -Picturesque food \ No newline at end of file +Picturesque food +{'baz'}