diff --git a/packages/vite/src/node/__tests__/utils.spec.ts b/packages/vite/src/node/__tests__/utils.spec.ts index 3efdbdd77c2409..35fdd3d3f97249 100644 --- a/packages/vite/src/node/__tests__/utils.spec.ts +++ b/packages/vite/src/node/__tests__/utils.spec.ts @@ -338,6 +338,13 @@ describe('processSrcSetSync', () => { 'data:image/avif;base64,aA+/0= 400w, data:image/avif;base64,bB+/9= 800w' expect(processSrcSetSync(base64, ({ url }) => url)).toBe(base64) }) + + test('should not break a regular URL in srcSet', async () => { + const source = 'https://anydomain/image.jpg' + expect( + processSrcSetSync('https://anydomain/image.jpg', ({ url }) => url), + ).toBe(source) + }) }) describe('flattenId', () => { diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 6f8004566cb6f9..bc85a3b38d37b4 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -767,7 +767,9 @@ interface ImageCandidate { const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g const imageSetUrlRE = /^(?:[\w\-]+\(.*?\)|'.*?'|".*?"|\S*)/ function joinSrcset(ret: ImageCandidate[]) { - return ret.map(({ url, descriptor }) => `${url} ${descriptor}`).join(', ') + return ret + .map(({ url, descriptor }) => url + (descriptor ? ` ${descriptor}` : '')) + .join(', ') } function splitSrcSetDescriptor(srcs: string): ImageCandidate[] {