diff --git a/.changeset/small-snakes-build.md b/.changeset/small-snakes-build.md new file mode 100644 index 000000000000..9f1c9f8ac0ec --- /dev/null +++ b/.changeset/small-snakes-build.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes remote images with encoded characters diff --git a/packages/astro/src/assets/utils/transformToPath.ts b/packages/astro/src/assets/utils/transformToPath.ts index affeea8eb4ac..dd8d17fbeaf3 100644 --- a/packages/astro/src/assets/utils/transformToPath.ts +++ b/packages/astro/src/assets/utils/transformToPath.ts @@ -10,7 +10,7 @@ export function propsToFilename(transform: ImageTransform, hash: string) { isESMImportedImage(transform.src) ? transform.src.src : transform.src ); const ext = extname(filename); - filename = basename(filename, ext); + filename = decodeURIComponent(basename(filename, ext)); let outputExt = transform.format ? `.${transform.format}` : ext; return `/${filename}_${hash}${outputExt}`; diff --git a/packages/astro/test/core-image.test.js b/packages/astro/test/core-image.test.js index 0d9b690b4817..9dcf0fae5666 100644 --- a/packages/astro/test/core-image.test.js +++ b/packages/astro/test/core-image.test.js @@ -747,7 +747,7 @@ describe('astro:image', () => { root: './fixtures/core-image-ssg/', image: { service: testImageService(), - domains: ['astro.build'], + domains: ['astro.build', 'avatars.githubusercontent.com'], }, }); // Remove cache directory @@ -945,6 +945,15 @@ describe('astro:image', () => { expect(data).to.be.an.instanceOf(Buffer); }); + it('supports images with encoded characters in url', async () => { + const html = await fixture.readFile('/index.html'); + const $ = cheerio.load(html); + const img = $('#encoded-chars img'); + const src = img.attr('src') + const data = await fixture.readFile(src); + expect(data).to.not.be.undefined; + }); + describe('custom service in build', () => { it('uses configured hashes properties', async () => { await fixture.build(); diff --git a/packages/astro/test/fixtures/core-image-ssg/public/documents/ProductCoverImages/ghost.webp b/packages/astro/test/fixtures/core-image-ssg/public/documents/ProductCoverImages/ghost.webp new file mode 100644 index 000000000000..9c5d391ac3ec Binary files /dev/null and b/packages/astro/test/fixtures/core-image-ssg/public/documents/ProductCoverImages/ghost.webp differ diff --git a/packages/astro/test/fixtures/core-image-ssg/src/pages/index.astro b/packages/astro/test/fixtures/core-image-ssg/src/pages/index.astro index d7f9b05519a5..43dc5613d2e8 100644 --- a/packages/astro/test/fixtures/core-image-ssg/src/pages/index.astro +++ b/packages/astro/test/fixtures/core-image-ssg/src/pages/index.astro @@ -14,5 +14,9 @@ import myImage from "../assets/penguin1.jpg";
fred
+ +
+ fred2 +