diff --git a/CHANGELOG.md b/CHANGELOG.md index bc36b2eb06..2b43394564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## Unreleased + +* Fix compiler exception with `a11y-img-redundant-alt` and value-less `alt` attribute ([#4777](https://github.com/sveltejs/svelte/issues/4777)) + ## 3.22.1 * Fix compiler exception with `a11y-img-redundant-alt` and dynamic `alt` attribute ([#4770](https://github.com/sveltejs/svelte/issues/4770)) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 5cda9919af..a337eff73a 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -488,7 +488,7 @@ export default class Element extends Node { if (alt_attribute && !aria_hidden_exist) { const alt_value = alt_attribute.get_static_value(); - if (alt_value && alt_value.match(/\b(image|picture|photo)\b/i)) { + if (/\b(image|picture|photo)\b/i.test(alt_value)) { 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 cd942ce2a0..a3528a5c41 100644 --- a/test/validator/samples/a11y-img-redundant-alt/input.svelte +++ b/test/validator/samples/a11y-img-redundant-alt/input.svelte @@ -6,3 +6,4 @@ Plant doing photosynthesis in the afternoon Picturesque food {'baz'} +