Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(assets): avoid splitting , inside base64 value of srcset attribute #15422

Merged
merged 7 commits into from Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/vite/src/node/__tests__/utils.spec.ts
Expand Up @@ -332,6 +332,14 @@ describe('processSrcSetSync', () => {
),
).toBe('/base/nested/asset.png 1x, /base/nested/asset.png 2x')
})

test('should not split the comma inside base64 value', async () => {
const base64 =
'data:image/avif;base64,AAAA 400w, data:image/avif;base64,BBBB 800w'
expect(processSrcSetSync(base64, ({ url }) => url)).toBe(base64)
})

test('should not split ')
chaejunlee marked this conversation as resolved.
Show resolved Hide resolved
})

describe('flattenId', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/utils.ts
Expand Up @@ -787,10 +787,10 @@ export function processSrcSetSync(
}

const cleanSrcSetRE =
/(?:url|image|gradient|cross-fade)\([^)]*\)|"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'/g
/(?:url|image|gradient|cross-fade)\([^)]*\)|"([^"]|(?<=\\)")*"|'([^']|(?<=\\)')*'|data:[/;,\w]+/g
bluwy marked this conversation as resolved.
Show resolved Hide resolved
function splitSrcSet(srcs: string) {
const parts: string[] = []
// There could be a ',' inside of url(data:...), linear-gradient(...) or "data:..."
// There could be a ',' inside of url(data:...), linear-gradient(...), "data:..." or data:...
const cleanedSrcs = srcs.replace(cleanSrcSetRE, blankReplacer)
let startIndex = 0
let splitIndex: number
Expand Down