Skip to content

Commit 4f9d2f4

Browse files
vjymisal0vijay-looprclaude
authored
fix(css): keep newline-separated srcset candidates intact (#23265)
Co-authored-by: vjymisal0 <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
1 parent 7bdad37 commit 4f9d2f4

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,18 @@ describe('processSrcSetSync', () => {
629629
expect(processSrcSetSync(source, ({ url }) => url)).toBe(result)
630630
})
631631

632+
test('should convert newline-separated srcset candidates to space-separated', async () => {
633+
const source = 'asset.png\n1x,\nnested/asset.png\n2x'
634+
const result = 'asset.png 1x, nested/asset.png 2x'
635+
expect(processSrcSetSync(source, ({ url }) => url)).toBe(result)
636+
})
637+
638+
test('should convert CRLF-separated srcset candidates to space-separated', async () => {
639+
const source = 'asset.png\r\n1x,\r\nnested/asset.png\r\n2x'
640+
const result = 'asset.png 1x, nested/asset.png 2x'
641+
expect(processSrcSetSync(source, ({ url }) => url)).toBe(result)
642+
})
643+
632644
test('should not break URLs with commas in image-set-options', async () => {
633645
const source = `url(https://example.com/dpr_1,f_auto,fl_progressive,q_auto,w_100/v1/img) 1x,
634646
url("https://example.com/dpr_2,f_auto,fl_progressive,q_auto,w_100/v1/img")\t\t2x

‎packages/vite/src/node/utils.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,6 @@ export function parseSrcset(string: string): ImageCandidate[] {
821821
const matches = string
822822
.trim()
823823
.replace(escapedSpaceCharacters, ' ')
824-
.replace(/\r?\n/, '')
825824
.replace(/,\s+/, ', ')
826825
.replaceAll(/\s+/g, ' ')
827826
.matchAll(imageCandidateRegex)

0 commit comments

Comments
 (0)