The design language that makes your AI harness better at design.
JavaScript
Broken images: a regex in a Svelte attribute expression stays a regex
Paul Bakaus1872eab8d955
diff --git a/crates/detect/src/regex_matchers.rs b/crates/detect/src/regex_matchers.rsindex 98fad7920..4ef46e472 100644--- a/crates/detect/src/regex_matchers.rs+++ b/crates/detect/src/regex_matchers.rs@@ -1918,9 +1918,7 @@ fn void_element(name: &[u8]) -> bool {.any(|v| name.eq_ignore_ascii_case(v))}-/// In Svelte and Vue (no nested tags), `{/` closes a block (`{/if}`); it-/// never opens a regex.-fn expression_frame(b: &[u8], start: usize, options: MarkupScanOptions) -> MarkupFrame {+fn expression_frame(start: usize, regex_can_start: bool) -> MarkupFrame {MarkupFrame::Expression {start,depth: 1,@@ -1928,7 +1926,7 @@ fn expression_frame(b: &[u8], start: usize, options: MarkupScanOptions) -> Markuescaped: false,line_comment: false,block_comment: false,- regex_can_start: options.nested_tags || b.get(start + 1) != Some(&b'/'),+ regex_can_start,word: Vec::new(),}}@@ -2140,7 +2138,10 @@ pub(crate) fn scan_markup_context(text: &str, options: MarkupScanOptions) -> Mar}if options.expressions && b[p] == b'{' {context[p] = MarkupContext::Expression;- stack.push(expression_frame(b, p, options));+ // In Svelte and Vue text, `{/` closes a block (`{/if}`);+ // it never opens a regex.+ let block_close = !options.nested_tags && b.get(p + 1) == Some(&b'/');+ stack.push(expression_frame(p, !block_close));}p += 1;}@@ -2178,7 +2179,7 @@ pub(crate) fn scan_markup_context(text: &str, options: MarkupScanOptions) -> Mar}b'{' if options.expressions => {context[p] = MarkupContext::Expression;- stack.push(expression_frame(b, p, options));+ stack.push(expression_frame(p, true));p += 1;}b'>' => {diff --git a/crates/detect/tests/broken_image_source.rs b/crates/detect/tests/broken_image_source.rsindex 848042739..fcdeba3a9 100644--- a/crates/detect/tests/broken_image_source.rs+++ b/crates/detect/tests/broken_image_source.rs@@ -11,6 +11,8 @@ fn source_images_distinguish_markup_from_bindings_and_code_literals() {("TooltipSameLine.svelte", include_str!("fixtures/broken-image/tooltip-same-line.svelte"), &[]),// A block closer (`{/if}`) is not the start of a regex.("Block.svelte", include_str!("fixtures/broken-image/block-close.svelte"), &[2]),+ // An attribute expression has no block closers: `{/` there is a regex.+ ("Title.svelte", include_str!("fixtures/broken-image/attribute-regex.svelte"), &[]),("View.astro", include_str!("fixtures/broken-image/shorthand.astro"), &[4]),// Elements nested in an expression, with apostrophes in their text.("List.astro", include_str!("fixtures/broken-image/expressions.astro"), &[4, 5]),diff --git a/crates/detect/tests/fixtures/broken-image/attribute-regex.svelte b/crates/detect/tests/fixtures/broken-image/attribute-regex.sveltenew file mode 100644index 000000000..1e6d384a6--- /dev/null+++ b/crates/detect/tests/fixtures/broken-image/attribute-regex.svelte@@ -0,0 +1 @@+<div title={/[}]<img>/.test(value)}></div>