Skip to content

Commit 7df34a3

Browse files
committed
apply changes from #16340 and #16341
1 parent 389cc32 commit 7df34a3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ import { roles as roles_map, aria } from 'aria-query';
3636
import { AXObjectRoles, elementAXObjects } from 'axobject-query';
3737
import {
3838
regex_heading_tags,
39+
regex_js_prefix,
3940
regex_not_whitespace,
41+
regex_redundant_img_alt,
4042
regex_starts_with_vowel,
4143
regex_whitespaces
4244
} from '../../../../patterns.js';
@@ -533,7 +535,9 @@ export function check_element(node, context) {
533535
}
534536
// no-autofocus
535537
case 'autofocus': {
536-
w.a11y_autofocus(attribute);
538+
if (node.name !== 'dialog' && !is_parent(context.path, ['dialog'])) {
539+
w.a11y_autofocus(attribute);
540+
}
537541
break;
538542
}
539543
// scope
@@ -673,7 +677,7 @@ export function check_element(node, context) {
673677
if (href) {
674678
const href_value = get_static_text_value(href);
675679
if (href_value !== null) {
676-
if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) {
680+
if (href_value === '' || href_value === '#' || regex_js_prefix.test(href_value)) {
677681
w.a11y_invalid_attribute(href, href_value, href.name);
678682
}
679683
}
@@ -715,7 +719,7 @@ export function check_element(node, context) {
715719
const alt_attribute = get_static_text_value(attribute_map.get('alt'));
716720
const aria_hidden = get_static_value(attribute_map.get('aria-hidden'));
717721
if (alt_attribute && !aria_hidden && !has_spread) {
718-
if (/\b(image|picture|photo)\b/i.test(alt_attribute)) {
722+
if (regex_redundant_img_alt.test(alt_attribute)) {
719723
w.a11y_img_redundant_alt(node);
720724
}
721725
}

packages/svelte/src/compiler/phases/patterns.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ export const regex_heading_tags = /^h[1-6]$/;
2323
export const regex_illegal_attribute_character = /(^[0-9-.])|[\^$@%&#?!|()[\]{}^*+~;]/;
2424
export const regex_bidirectional_control_characters =
2525
/[\u202a\u202b\u202c\u202d\u202e\u2066\u2067\u2068\u2069]+/g;
26+
export const regex_js_prefix = /^\W*javascript:/i;
27+
export const regex_redundant_img_alt = /\b(image|picture|photo)\b/i;

0 commit comments

Comments
 (0)