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: access to pages with non ascii filenames #3841

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions lib/core/middleware/nuxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { getContext } from '../../common/utils'
export default async function nuxtMiddleware(req, res, next) {
// Get context
const context = getContext(req, res)
const url = decodeURIComponent(req.url)

res.statusCode = 200
try {
const result = await this.renderRoute(req.url, context)
await this.nuxt.callHook('render:route', req.url, result, context)
const result = await this.renderRoute(url, context)
await this.nuxt.callHook('render:route', url, result, context)
const {
html,
cspScriptSrcHashSet,
Expand All @@ -21,7 +22,7 @@ export default async function nuxtMiddleware(req, res, next) {
} = result

if (redirected) {
this.nuxt.callHook('render:routeDone', req.url, result, context)
this.nuxt.callHook('render:routeDone', url, result, context)
return html
}
if (error) {
Expand All @@ -34,7 +35,7 @@ export default async function nuxtMiddleware(req, res, next) {
if (fresh(req.headers, { etag })) {
res.statusCode = 304
res.end()
this.nuxt.callHook('render:routeDone', req.url, result, context)
this.nuxt.callHook('render:routeDone', url, result, context)
return
}
res.setHeader('ETag', etag)
Expand Down Expand Up @@ -81,7 +82,7 @@ export default async function nuxtMiddleware(req, res, next) {
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.setHeader('Content-Length', Buffer.byteLength(html))
res.end(html, 'utf8')
this.nuxt.callHook('render:routeDone', req.url, result, context)
this.nuxt.callHook('render:routeDone', url, result, context)
return html
} catch (err) {
/* istanbul ignore if */
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/spa/pages/тест雨.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div>Hello SPA!</div>
</template>

<script>
export default {
mounted() {
window.indexMounted = (+window.indexMounted) + 1
console.log('mounted') // eslint-disable-line no-console
}
}
</script>
8 changes: 8 additions & 0 deletions test/unit/spa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ describe('spa', () => {
consola.log.mockClear()
})

test('/тест雨 (test non ascii route)', async () => {
const { html } = await renderRoute('/тест雨')
expect(html).toMatch('Hello SPA!')
expect(consola.log).not.toHaveBeenCalledWith('created')
expect(consola.log).toHaveBeenCalledWith('mounted')
consola.log.mockClear()
})

test('/custom (custom layout)', async () => {
const { html } = await renderRoute('/custom')
expect(html).toMatch('Custom layout')
Expand Down