Skip to content

Commit 8de7bd2

Browse files
authored
fix(assets): avoid splitting , inside base64 value of srcset attribute (#15422)
1 parent 56ae92c commit 8de7bd2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ describe('processSrcSetSync', () => {
332332
),
333333
).toBe('/base/nested/asset.png 1x, /base/nested/asset.png 2x')
334334
})
335+
336+
test('should not split the comma inside base64 value', async () => {
337+
const base64 =
338+
'data:image/avif;base64,aA+/0= 400w, data:image/avif;base64,bB+/9= 800w'
339+
expect(processSrcSetSync(base64, ({ url }) => url)).toBe(base64)
340+
})
335341
})
336342

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

packages/vite/src/node/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,10 @@ export function processSrcSetSync(
787787
}
788788

789789
const cleanSrcSetRE =
790-
/(?:url|image|gradient|cross-fade)\([^)]*\)|"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'/g
790+
/(?:url|image|gradient|cross-fade)\([^)]*\)|"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'|data:\w+\/[\w.+\-]+;base64,[\w+/=]+/g
791791
function splitSrcSet(srcs: string) {
792792
const parts: string[] = []
793-
// There could be a ',' inside of url(data:...), linear-gradient(...) or "data:..."
793+
// There could be a ',' inside of url(data:...), linear-gradient(...), "data:..." or data:...
794794
const cleanedSrcs = srcs.replace(cleanSrcSetRE, blankReplacer)
795795
let startIndex = 0
796796
let splitIndex: number

0 commit comments

Comments
 (0)