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(indexHtml): decode html URI #13581

Merged
merged 3 commits into from Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/html.ts
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
6 changes: 5 additions & 1 deletion packages/vite/src/node/server/middlewares/indexHtml.ts
Expand Up @@ -331,7 +331,11 @@ export function indexHtmlMiddleware(
if (fs.existsSync(filename)) {
try {
let html = await fsp.readFile(filename, 'utf-8')
html = await server.transformIndexHtml(url, html, req.originalUrl)
html = await server.transformIndexHtml(
decodeURI(url),
sun0day marked this conversation as resolved.
Show resolved Hide resolved
html,
req.originalUrl,
)
return send(req, res, html, 'html', {
headers: server.config.server.headers,
})
Expand Down
10 changes: 10 additions & 0 deletions playground/html/__tests__/html.spec.ts
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
@@ -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
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