Skip to content

Commit 81b3bd0

Browse files
fix: srcSet with optional descriptor (#15905)
Co-authored-by: patak <[email protected]>
1 parent 571a3fd commit 81b3bd0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/vite/src/node/__tests__/utils.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ describe('processSrcSetSync', () => {
338338
'data:image/avif;base64,aA+/0= 400w, data:image/avif;base64,bB+/9= 800w'
339339
expect(processSrcSetSync(base64, ({ url }) => url)).toBe(base64)
340340
})
341+
342+
test('should not break a regular URL in srcSet', async () => {
343+
const source = 'https://anydomain/image.jpg'
344+
expect(
345+
processSrcSetSync('https://anydomain/image.jpg', ({ url }) => url),
346+
).toBe(source)
347+
})
341348
})
342349

343350
describe('flattenId', () => {

packages/vite/src/node/utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,9 @@ interface ImageCandidate {
767767
const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g
768768
const imageSetUrlRE = /^(?:[\w\-]+\(.*?\)|'.*?'|".*?"|\S*)/
769769
function joinSrcset(ret: ImageCandidate[]) {
770-
return ret.map(({ url, descriptor }) => `${url} ${descriptor}`).join(', ')
770+
return ret
771+
.map(({ url, descriptor }) => url + (descriptor ? ` ${descriptor}` : ''))
772+
.join(', ')
771773
}
772774

773775
function splitSrcSetDescriptor(srcs: string): ImageCandidate[] {

0 commit comments

Comments
 (0)