Skip to content

Commit bdabd89

Browse files
authored
fix exception with empty alt attribute (#4778)
1 parent bb5e2d2 commit bdabd89

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Svelte changelog
22

3+
## Unreleased
4+
5+
* Fix compiler exception with `a11y-img-redundant-alt` and value-less `alt` attribute ([#4777](https://github.com/sveltejs/svelte/issues/4777))
6+
37
## 3.22.1
48

59
* Fix compiler exception with `a11y-img-redundant-alt` and dynamic `alt` attribute ([#4770](https://github.com/sveltejs/svelte/issues/4770))

src/compiler/compile/nodes/Element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ export default class Element extends Node {
488488
if (alt_attribute && !aria_hidden_exist) {
489489
const alt_value = alt_attribute.get_static_value();
490490

491-
if (alt_value && alt_value.match(/\b(image|picture|photo)\b/i)) {
491+
if (/\b(image|picture|photo)\b/i.test(alt_value)) {
492492
component.warn(this, {
493493
code: `a11y-img-redundant-alt`,
494494
message: `A11y: Screenreaders already announce <img> elements as an image.`

test/validator/samples/a11y-img-redundant-alt/input.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
<img src="bar" alt="Plant doing photosynthesis in the afternoon" />
77
<img src="foo" alt="Picturesque food" />
88
<img src="baz" alt={'baz'} />
9+
<img src="baz" alt />

0 commit comments

Comments
 (0)