Skip to content

Commit

Permalink
fix(indexHtml): decode html URI (#13581)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun0day authored Jun 22, 2023
1 parent 17c63fe commit f8868af
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function htmlInlineProxyPlugin(config: ResolvedConfig): Plugin {
const index = Number(proxyMatch[1])
const file = cleanUrl(id)
const url = file.replace(normalizePath(config.root), '')
const result = htmlProxyMap.get(config)!.get(url)![index]
const result = htmlProxyMap.get(config)!.get(url)?.[index]
if (result) {
return result
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const devHtmlHook: IndexHtmlTransformHook = async (
) => {
const { config, moduleGraph, watcher } = server!
const base = config.base || '/'
htmlPath = decodeURI(htmlPath)

let proxyModulePath: string
let proxyModuleUrl: string
Expand Down
10 changes: 10 additions & 0 deletions playground/html/__tests__/html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,13 @@ describe('side-effects', () => {
expect(browserLogs).toContain('message from sideEffects script')
})
})

describe('special character', () => {
beforeAll(async () => {
await page.goto(viteTestUrl + '/a á.html')
})

test('should fetch html proxy', async () => {
expect(browserLogs).toContain('special character')
})
})
5 changes: 5 additions & 0 deletions playground/html/a á.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Special Character</h1>

<script type="module">
console.log('special character')
</script>
1 change: 1 addition & 0 deletions playground/html/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default defineConfig({
importmapOrder: resolve(__dirname, 'importmapOrder.html'),
env: resolve(__dirname, 'env.html'),
sideEffects: resolve(__dirname, 'side-effects/index.html'),
'a á': resolve(__dirname, 'a á.html'),
},
},
},
Expand Down

0 comments on commit f8868af

Please sign in to comment.