Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-months-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a bug where Astro couldn't probably use `inferSize` for images that contain apostrophe `'` in their name.
8 changes: 4 additions & 4 deletions packages/astro/src/vite-plugin-markdown/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function getMarkdownCodeForImages(
const imageSources = {};
${localImagePaths
.map((entry) => {
const rawUrl = JSON.stringify(entry.raw);
const rawUrl = JSON.stringify(entry.raw).replace(/'/g, ''');
return `{
const regex = new RegExp('__ASTRO_IMAGE_="([^"]*' + ${rawUrl.replace(
/[.*+?^${}()|[\]\\]/g,
Expand All @@ -25,7 +25,7 @@ export function getMarkdownCodeForImages(
let occurrenceCounter = 0;
while ((match = regex.exec(html)) !== null) {
const matchKey = ${rawUrl} + '_' + occurrenceCounter;
const imageProps = JSON.parse(match[1].replace(/"/g, '"'));
const imageProps = JSON.parse(match[1].replace(/"/g, '"').replace(/'/g, "'"));
const { src, ...props } = imageProps;
imageSources[matchKey] = await getImage({src: Astro__${entry.safeName}, ...props});
occurrenceCounter++;
Expand All @@ -35,7 +35,7 @@ export function getMarkdownCodeForImages(
.join('\n')}
${remoteImagePaths
.map((raw) => {
const rawUrl = JSON.stringify(raw);
const rawUrl = JSON.stringify(raw).replace(/'/g, ''');
return `{
const regex = new RegExp('__ASTRO_IMAGE_="([^"]*' + ${rawUrl.replace(
/[.*+?^${}()|[\]\\]/g,
Expand All @@ -45,7 +45,7 @@ export function getMarkdownCodeForImages(
let occurrenceCounter = 0;
while ((match = regex.exec(html)) !== null) {
const matchKey = ${rawUrl} + '_' + occurrenceCounter;
const props = JSON.parse(match[1].replace(/"/g, '"'));
const props = JSON.parse(match[1].replace(/"/g, '"').replace(/'/g, "'"));
imageSources[matchKey] = await getImage(props);
occurrenceCounter++;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/core-image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ describe('astro:image', () => {
$ = cheerio.load(html);

let $img = $('img');
assert.equal($img.length, 3);
assert.equal($img.length, 4);
$img.each((_, el) => {
assert.equal(el.attribs.src?.startsWith('/_image'), true);
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
![C++](../assets/c++.png)
![Penguin with space](../assets/penguin%20with%20space.jpg)
![Penguin with percent](../assets/penguin%20with%20percent%25.jpg)
![Penguin with apostrophe](../assets/penguin%20with%20apostrophe%27.jpg)

Image with special characters in file name worked.