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:

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

Fixes #7741.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2023-07-20 22:59:10 -07:00 committed by GitHub
parent 379981efdc
commit e528526289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix parsing image assets from a Markdown line along with other markup.

View file

@ -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})
);
}