The design language that makes your AI harness better at design.
JavaScript
Broken images: a tag comment is not a self-closing slash, and {/if} is not a regex
Paul Bakaus52d2f28bb6b0
diff --git a/crates/detect/src/regex_matchers.rs b/crates/detect/src/regex_matchers.rsindex 9d60d8ace..98fad7920 100644--- a/crates/detect/src/regex_matchers.rs+++ b/crates/detect/src/regex_matchers.rs@@ -1918,7 +1918,9 @@ fn void_element(name: &[u8]) -> bool {.any(|v| name.eq_ignore_ascii_case(v))}-fn expression_frame(start: usize) -> MarkupFrame {+/// 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 {MarkupFrame::Expression {start,depth: 1,@@ -1926,7 +1928,7 @@ fn expression_frame(start: usize) -> MarkupFrame {escaped: false,line_comment: false,block_comment: false,- regex_can_start: true,+ regex_can_start: options.nested_tags || b.get(start + 1) != Some(&b'/'),word: Vec::new(),}}@@ -2138,7 +2140,7 @@ 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(p));+ stack.push(expression_frame(b, p, options));}p += 1;}@@ -2176,7 +2178,7 @@ pub(crate) fn scan_markup_context(text: &str, options: MarkupScanOptions) -> Mar}b'{' if options.expressions => {context[p] = MarkupContext::Expression;- stack.push(expression_frame(p));+ stack.push(expression_frame(b, p, options));p += 1;}b'>' => {@@ -2232,7 +2234,10 @@ pub(crate) fn scan_markup_context(text: &str, options: MarkupScanOptions) -> Marc => {context[p] = MarkupContext::Tag;if !c.is_ascii_whitespace() {- *last_non_space = Some(c);+ // The `/` closing a `/* comment */` is not a+ // self-closing slash.+ let ends_comment = c == b'/' && *last_non_space == Some(b'*');+ *last_non_space = Some(if ends_comment { 0 } else { c });}p += 1;}diff --git a/crates/detect/tests/broken_image_source.rs b/crates/detect/tests/broken_image_source.rsindex 27617f6e6..848042739 100644--- a/crates/detect/tests/broken_image_source.rs+++ b/crates/detect/tests/broken_image_source.rs@@ -9,6 +9,8 @@ fn source_images_distinguish_markup_from_bindings_and_code_literals() {("View.svelte", include_str!("fixtures/broken-image/shorthand.svelte"), &[5, 6, 7, 11, 12]),("TooltipMultiline.svelte", include_str!("fixtures/broken-image/tooltip-multiline.svelte"), &[]),("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]),("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]),@@ -23,7 +25,7 @@ fn source_images_distinguish_markup_from_bindings_and_code_literals() {("View.jsx", include_str!("fixtures/broken-image/elements.jsx"), &[5, 6, 11, 14, 18, 19, 21, 29]),("View.tsx", include_str!("fixtures/broken-image/elements.jsx"), &[5, 6, 11, 14, 18, 19, 21, 29]),// JSX children text (`Don't`, a URL, `and/or`) is text, not code.- ("Body.tsx", include_str!("fixtures/broken-image/children-text.tsx"), &[7, 10]),+ ("Body.tsx", include_str!("fixtures/broken-image/children-text.tsx"), &[7, 10, 15]),];for &(path, source, expected) in cases {let findings = detect_text(source, path, &TextOptions::default());diff --git a/crates/detect/tests/fixtures/broken-image/block-close.svelte b/crates/detect/tests/fixtures/broken-image/block-close.sveltenew file mode 100644index 000000000..95a4071f9--- /dev/null+++ b/crates/detect/tests/fixtures/broken-image/block-close.svelte@@ -0,0 +1,2 @@+<script>let show = true; let count = 4;</script>+{#if show}<span>Hi</span>{/if}<img alt="missing">{count / 2}diff --git a/crates/detect/tests/fixtures/broken-image/children-text.tsx b/crates/detect/tests/fixtures/broken-image/children-text.tsxindex 1de2d97f2..2188d77ec 100644--- a/crates/detect/tests/fixtures/broken-image/children-text.tsx+++ b/crates/detect/tests/fixtures/broken-image/children-text.tsx@@ -11,3 +11,6 @@ export function A({ items }) {</>);}+export function L({ items }) {+ return items.map((i) => <li /* note */><img alt="c" /></li>);+}