Skip to content

Commit f8868af

Browse files
authored
fix(indexHtml): decode html URI (#13581)
1 parent 17c63fe commit f8868af

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function htmlInlineProxyPlugin(config: ResolvedConfig): Plugin {
9797
const index = Number(proxyMatch[1])
9898
const file = cleanUrl(id)
9999
const url = file.replace(normalizePath(config.root), '')
100-
const result = htmlProxyMap.get(config)!.get(url)![index]
100+
const result = htmlProxyMap.get(config)!.get(url)?.[index]
101101
if (result) {
102102
return result
103103
} else {

packages/vite/src/node/server/middlewares/indexHtml.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const devHtmlHook: IndexHtmlTransformHook = async (
150150
) => {
151151
const { config, moduleGraph, watcher } = server!
152152
const base = config.base || '/'
153+
htmlPath = decodeURI(htmlPath)
153154

154155
let proxyModulePath: string
155156
let proxyModuleUrl: string

playground/html/__tests__/html.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,13 @@ describe('side-effects', () => {
303303
expect(browserLogs).toContain('message from sideEffects script')
304304
})
305305
})
306+
307+
describe('special character', () => {
308+
beforeAll(async () => {
309+
await page.goto(viteTestUrl + '/a á.html')
310+
})
311+
312+
test('should fetch html proxy', async () => {
313+
expect(browserLogs).toContain('special character')
314+
})
315+
})

playground/html/a á.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h1>Special Character</h1>
2+
3+
<script type="module">
4+
console.log('special character')
5+
</script>

playground/html/vite.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default defineConfig({
2929
importmapOrder: resolve(__dirname, 'importmapOrder.html'),
3030
env: resolve(__dirname, 'env.html'),
3131
sideEffects: resolve(__dirname, 'side-effects/index.html'),
32+
'a á': resolve(__dirname, 'a á.html'),
3233
},
3334
},
3435
},

0 commit comments

Comments
 (0)