Skip to content

Commit 53f1ce7

Browse files
fix(html): resolve percent-encoded srcset urls (#23609)
Co-authored-by: sapphi-red <[email protected]>
1 parent 744269e commit 53f1ce7

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎packages/vite/src/node/plugins/html.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
654654
!isExcludedUrl(decodedUrl)
655655
) {
656656
const result = await processAssetUrl(
657-
url,
657+
decodedUrl,
658658
getLinkShouldInline(node, attr.attributes),
659659
)
660660
return result !== decodedUrl

‎playground/assets/__tests__/assets.spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,14 @@ describe.runIf(isBuild)('encodeURI', () => {
672672
const img = await page.$('.encodeURI')
673673
expect(await img.getAttribute('src')).toMatch(/^data:image\/png;base64,/)
674674
})
675+
676+
test('img srcset with encodeURI', async () => {
677+
const img = await page.$('.encodeURI')
678+
const srcset = await img.getAttribute('srcset')
679+
srcset.split(', ').forEach((candidate) => {
680+
expect(candidate).toMatch(/^data:image\/png;base64,\S+ \dx$/)
681+
})
682+
})
675683
})
676684

677685
test('new URL(..., import.meta.url)', async () => {

‎playground/assets/index.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ <h2>encodeURI for the address</h2>
219219
<img
220220
class="encodeURI"
221221
src="./nested/%E3%83%86%E3%82%B9%E3%83%88-%E6%B8%AC%E8%A9%A6-white%20space.png"
222+
srcset="
223+
./nested/%E3%83%86%E3%82%B9%E3%83%88-%E6%B8%AC%E8%A9%A6-white%20space.png 1x,
224+
./nested/%E3%83%86%E3%82%B9%E3%83%88-%E6%B8%AC%E8%A9%A6-white%20space.png 2x
225+
"
222226
/>
223227
</div>
224228

0 commit comments

Comments
 (0)