mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
Support remote images with encoded characters (#9540)
* Support remote images with encoded characters * Add a changeset * Update .changeset/small-snakes-build.md Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> --------- Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
This commit is contained in:
parent
b34bd2b2d9
commit
7f212f0831
5 changed files with 20 additions and 2 deletions
5
.changeset/small-snakes-build.md
Normal file
5
.changeset/small-snakes-build.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Fixes remote images with encoded characters
|
|
@ -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}`;
|
||||
|
|
|
@ -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();
|
||||
|
|
BIN
packages/astro/test/fixtures/core-image-ssg/public/documents/ProductCoverImages/ghost.webp
vendored
Normal file
BIN
packages/astro/test/fixtures/core-image-ssg/public/documents/ProductCoverImages/ghost.webp
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
|
@ -14,5 +14,9 @@ import myImage from "../assets/penguin1.jpg";
|
|||
<div id="remote">
|
||||
<Image src="https://avatars.githubusercontent.com/u/622227?s=64" alt="fred" width="48" height="48" />
|
||||
</div>
|
||||
|
||||
<div id="encoded-chars">
|
||||
<Image src="https://avatars.githubusercontent.com/u%2f622227?s=64" alt="fred2" width="48" height="48" />
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Reference in a new issue