fix: make Picture generate valid dev URLs (#7500)

This commit is contained in:
Wooseop Kim 2023-07-03 17:09:40 +09:00 committed by GitHub
parent 3df71fd34f
commit e644b34659
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/image": patch
---
fix: make `Picture` generate valid dev URLs

View file

@ -85,7 +85,7 @@ export async function getPicture(params: GetPictureParams): Promise<GetPictureRe
image = img; image = img;
} }
return `${encodeURI(img.src ?? '')} ${width}w`; return `${img.src?.replaceAll(' ', encodeURI)} ${width}w`;
}) })
); );

View file

@ -195,6 +195,16 @@ describe('SSG pictures with subpath - dev', function () {
const src = image.attr('src'); const src = image.attr('src');
const [route, params] = src.split('?'); const [route, params] = src.split('?');
for (const srcset of picture.children('source').map((_, source) => source.attribs['srcset'])) {
for (const pictureSrc of srcset.split(',')) {
const pictureParams = pictureSrc.split('?')[1];
const expected = new URLSearchParams(params).get('href');
const actual = new URLSearchParams(pictureParams).get('href').replace(/\s+\d+w$/, '');
expect(expected).to.equal(actual);
}
}
expect(route).to.equal(url); expect(route).to.equal(url);
const searchParams = new URLSearchParams(params); const searchParams = new URLSearchParams(params);

View file

@ -223,6 +223,16 @@ describe('SSR pictures with subpath - build', function () {
const src = image.attr('src'); const src = image.attr('src');
const [route, params] = src.split('?'); const [route, params] = src.split('?');
for (const srcset of picture.children('source').map((_, source) => source.attribs['srcset'])) {
for (const pictureSrc of srcset.split(',')) {
const pictureParams = pictureSrc.split('?')[1];
const expected = new URLSearchParams(params).get('href');
const actual = new URLSearchParams(pictureParams).get('href').replace(/\s+\d+w$/, '');
expect(expected).to.equal(actual);
}
}
expect(route).to.equal(url); expect(route).to.equal(url);
const searchParams = new URLSearchParams(params); const searchParams = new URLSearchParams(params);

View file

@ -127,6 +127,16 @@ describe('SSR pictures - dev', function () {
const src = image.attr('src'); const src = image.attr('src');
const [route, params] = src.split('?'); const [route, params] = src.split('?');
for (const srcset of picture.children('source').map((_, source) => source.attribs['srcset'])) {
for (const pictureSrc of srcset.split(',')) {
const pictureParams = pictureSrc.split('?')[1];
const expected = new URLSearchParams(params).get('href');
const actual = new URLSearchParams(pictureParams).get('href').replace(/\s+\d+w$/, '');
expect(expected).to.equal(actual);
}
}
expect(route).to.equal(url); expect(route).to.equal(url);
const searchParams = new URLSearchParams(params); const searchParams = new URLSearchParams(params);