From e528526289dd9fba98e254743ded47a5c6d418a8 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 20 Jul 2023 22:59:10 -0700 Subject: [PATCH] Fix parsing image assets from a Markdown line along with other markup (#7742) Every regex that tries to match a substring with .* or .+ is guaranteed to be wrong. In this case, it was giving incorrect matches straddling multiple quoted attributes: and link ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Fixes #7741. Signed-off-by: Anders Kaseorg --- .changeset/five-phones-notice.md | 5 +++++ packages/astro/src/vite-plugin-markdown/index.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/five-phones-notice.md diff --git a/.changeset/five-phones-notice.md b/.changeset/five-phones-notice.md new file mode 100644 index 0000000000..7973ac6118 --- /dev/null +++ b/.changeset/five-phones-notice.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix parsing image assets from a Markdown line along with other markup. diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index fcdaf04ea1..3d82024220 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -147,7 +147,7 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu function updateImageReferences(html) { return html.replaceAll( - /__ASTRO_IMAGE_=\"(.+)\"/gm, + /__ASTRO_IMAGE_="([^"]+)"/gm, (full, imagePath) => spreadAttributes({src: images[imagePath].src, ...images[imagePath].attributes}) ); }