fix: make Picture
generate valid dev URLs (#7500)
This commit is contained in:
parent
3df71fd34f
commit
e644b34659
5 changed files with 36 additions and 1 deletions
5
.changeset/few-ants-brake.md
Normal file
5
.changeset/few-ants-brake.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/image": patch
|
||||
---
|
||||
|
||||
fix: make `Picture` generate valid dev URLs
|
|
@ -85,7 +85,7 @@ export async function getPicture(params: GetPictureParams): Promise<GetPictureRe
|
|||
image = img;
|
||||
}
|
||||
|
||||
return `${encodeURI(img.src ?? '')} ${width}w`;
|
||||
return `${img.src?.replaceAll(' ', encodeURI)} ${width}w`;
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
@ -195,6 +195,16 @@ describe('SSG pictures with subpath - dev', function () {
|
|||
const src = image.attr('src');
|
||||
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);
|
||||
|
||||
const searchParams = new URLSearchParams(params);
|
||||
|
|
|
@ -223,6 +223,16 @@ describe('SSR pictures with subpath - build', function () {
|
|||
const src = image.attr('src');
|
||||
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);
|
||||
|
||||
const searchParams = new URLSearchParams(params);
|
||||
|
|
|
@ -127,6 +127,16 @@ describe('SSR pictures - dev', function () {
|
|||
const src = image.attr('src');
|
||||
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);
|
||||
|
||||
const searchParams = new URLSearchParams(params);
|
||||
|
|
Loading…
Reference in a new issue