From e543a07bc8ad83e76316fc33d9b0e01acd67bdc2 Mon Sep 17 00:00:00 2001 From: navorite Date: Fri, 11 Jul 2025 07:59:01 +0300 Subject: [PATCH 1/4] chore: replace inline regex with variable --- .changeset/tiny-news-whisper.md | 5 +++++ .../src/compiler/phases/2-analyze/visitors/shared/a11y.js | 6 ++++-- packages/svelte/src/compiler/phases/patterns.js | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/tiny-news-whisper.md diff --git a/.changeset/tiny-news-whisper.md b/.changeset/tiny-news-whisper.md new file mode 100644 index 000000000000..8bf877085d30 --- /dev/null +++ b/.changeset/tiny-news-whisper.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +chore: replace inline regex with variable diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js index 1f58a28cad73..445a288f75ac 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js @@ -6,7 +6,9 @@ import { roles as roles_map, aria, elementRoles } from 'aria-query'; import { AXObjects, AXObjectRoles, elementAXObjects } from 'axobject-query'; import { regex_heading_tags, + regex_js_code, regex_not_whitespace, + regex_redundant_img_alt, regex_starts_with_vowel, regex_whitespaces } from '../../../patterns.js'; @@ -1011,7 +1013,7 @@ export function check_element(node, context) { if (href) { const href_value = get_static_text_value(href); if (href_value !== null) { - if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) { + if (href_value === '' || href_value === '#' || regex_js_code.test(href_value)) { w.a11y_invalid_attribute(href, href_value, href.name); } } @@ -1061,7 +1063,7 @@ export function check_element(node, context) { const alt_attribute = get_static_text_value(attribute_map.get('alt')); const aria_hidden = get_static_value(attribute_map.get('aria-hidden')); if (alt_attribute && !aria_hidden && !has_spread) { - if (/\b(image|picture|photo)\b/i.test(alt_attribute)) { + if (regex_redundant_img_alt.test(alt_attribute)) { w.a11y_img_redundant_alt(node); } } diff --git a/packages/svelte/src/compiler/phases/patterns.js b/packages/svelte/src/compiler/phases/patterns.js index 2bee717131c7..d9d629f81e10 100644 --- a/packages/svelte/src/compiler/phases/patterns.js +++ b/packages/svelte/src/compiler/phases/patterns.js @@ -23,3 +23,5 @@ export const regex_heading_tags = /^h[1-6]$/; export const regex_illegal_attribute_character = /(^[0-9-.])|[\^$@%&#?!|()[\]{}^*+~;]/; export const regex_bidirectional_control_characters = /[\u202a\u202b\u202c\u202d\u202e\u2066\u2067\u2068\u2069]+/g; +export const regex_js_code = /^\W*javascript:/i; +export const regex_redundant_img_alt = /\b(image|picture|photo)\b/i; From 70a2592c79008af3165ef587f50b86b971dd70af Mon Sep 17 00:00:00 2001 From: "Ahmad S." Date: Fri, 11 Jul 2025 20:00:05 +0300 Subject: [PATCH 2/4] Update packages/svelte/src/compiler/phases/patterns.js Co-authored-by: ComputerGuy <63362464+Ocean-OS@users.noreply.github.com> --- packages/svelte/src/compiler/phases/patterns.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/patterns.js b/packages/svelte/src/compiler/phases/patterns.js index d9d629f81e10..448be7f9499f 100644 --- a/packages/svelte/src/compiler/phases/patterns.js +++ b/packages/svelte/src/compiler/phases/patterns.js @@ -23,5 +23,5 @@ export const regex_heading_tags = /^h[1-6]$/; export const regex_illegal_attribute_character = /(^[0-9-.])|[\^$@%&#?!|()[\]{}^*+~;]/; export const regex_bidirectional_control_characters = /[\u202a\u202b\u202c\u202d\u202e\u2066\u2067\u2068\u2069]+/g; -export const regex_js_code = /^\W*javascript:/i; +export const regex_js_prefix = /^\W*javascript:/i; export const regex_redundant_img_alt = /\b(image|picture|photo)\b/i; From eda506bf71c6a69d63d134781c83d77afd9c9312 Mon Sep 17 00:00:00 2001 From: "Ahmad S." Date: Fri, 11 Jul 2025 20:00:41 +0300 Subject: [PATCH 3/4] Update a11y.js --- .../src/compiler/phases/2-analyze/visitors/shared/a11y.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js index 445a288f75ac..5164bb9f117f 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js @@ -1013,7 +1013,7 @@ export function check_element(node, context) { if (href) { const href_value = get_static_text_value(href); if (href_value !== null) { - if (href_value === '' || href_value === '#' || regex_js_code.test(href_value)) { + if (href_value === '' || href_value === '#' || regex_js_prefix.test(href_value)) { w.a11y_invalid_attribute(href, href_value, href.name); } } From c5d9fe5607c0a8b8b02826f375a3beee26f3aa9b Mon Sep 17 00:00:00 2001 From: "Ahmad S." Date: Fri, 11 Jul 2025 20:06:11 +0300 Subject: [PATCH 4/4] Update a11y.js --- .../src/compiler/phases/2-analyze/visitors/shared/a11y.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js index 5164bb9f117f..e103e3eb80f7 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js @@ -6,7 +6,7 @@ import { roles as roles_map, aria, elementRoles } from 'aria-query'; import { AXObjects, AXObjectRoles, elementAXObjects } from 'axobject-query'; import { regex_heading_tags, - regex_js_code, + regex_js_prefix, regex_not_whitespace, regex_redundant_img_alt, regex_starts_with_vowel,