Skip to content

Commit

Permalink
Fix parsing image assets from a Markdown line along with other markup (
Browse files Browse the repository at this point in the history
…#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:

    <img __ASTRO_IMAGE_="../assets/image.png"> and <a href="link">link</a>
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Fixes #7741.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
andersk authored Jul 21, 2023
1 parent 379981e commit e528526
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/five-phones-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix parsing image assets from a Markdown line along with other markup.
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})
);
}
Expand Down

0 comments on commit e528526

Please sign in to comment.