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: allow unicode page names #4402

Merged
merged 2 commits into from
Nov 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 packages/server/src/middleware/nuxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { getContext } from '@nuxt/common'
export default ({ options, nuxt, renderRoute, resources }) => async function nuxtMiddleware(req, res, next) {
// Get context
const context = getContext(req, res)
const url = req.url

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

if (redirected) {
nuxt.callHook('render:routeDone', req.url, result, context)
nuxt.callHook('render:routeDone', url, result, context)
return html
}
if (error) {
Expand All @@ -34,7 +35,7 @@ export default ({ options, nuxt, renderRoute, resources }) => async function nux
if (fresh(req.headers, { etag })) {
res.statusCode = 304
res.end()
nuxt.callHook('render:routeDone', req.url, result, context)
nuxt.callHook('render:routeDone', url, result, context)
return
}
res.setHeader('ETag', etag)
Expand Down Expand Up @@ -73,7 +74,7 @@ export default ({ options, nuxt, renderRoute, resources }) => async function nux
res.setHeader('Accept-Ranges', 'none') // #3870
res.setHeader('Content-Length', Buffer.byteLength(html))
res.end(html, 'utf8')
nuxt.callHook('render:routeDone', req.url, result, context)
nuxt.callHook('render:routeDone', url, result, context)
return html
} catch (err) {
/* istanbul ignore if */
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"version": "2.3.2",
"repository": "nuxt/nuxt.js",
"license": "MIT",
"typings": "types/index.d.ts",
"files": [
"dist",
"template",
"types/*.d.ts"
],
"main": "dist/vue-app.js",
"typings": "types/index.d.ts",
manniL marked this conversation as resolved.
Show resolved Hide resolved
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-app/template/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export function getLocation(base, mode) {
if (base && path.indexOf(base) === 0) {
path = path.slice(base.length)
}
return (path || '/') + window.location.search + window.location.hash
return decodeURI(path || '/') + window.location.search + window.location.hash
}

export function urlJoin() {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/basic/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default {
'/store-module',
'/users/1',
'/users/2',
'/тест雨',
{ route: '/users/3', payload: { id: 3000 } }
],
interval: 200,
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/basic/pages/тест雨.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Hello unicode!</div>
</template>
3 changes: 3 additions & 0 deletions test/fixtures/spa/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default {
}
},
build: {
optimization: {
minimize: false
aldarund marked this conversation as resolved.
Show resolved Hide resolved
},
filenames: {
app: '[name].js',
chunk: '[name].js'
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/spa/pages/тест雨.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>Hello unicode SPA!</div>
</template>
<script>
export default {
mounted() {
window.indexMounted = (+window.indexMounted) + 1
console.log('mounted') // eslint-disable-line no-console
}
}
</script>
6 changes: 6 additions & 0 deletions test/unit/basic.generate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ describe('basic generate', () => {
expect(html).toContain('<p>Nuxt.js</p>')
})

test('/тест雨 (test non ascii route)', async () => {
const window = await generator.nuxt.server.renderAndGetWindow(url('/тест雨'))
const html = window.document.body.innerHTML
expect(html).toContain('Hello unicode')
})

test('/users/1/index.html', async () => {
const html = await rp(url('/users/1/index.html'))
expect(html).toContain('<h1>User: 1</h1>')
Expand Down
5 changes: 5 additions & 0 deletions test/unit/basic.ssr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ describe('basic ssr', () => {
expect(html).toContain('<h1>vue file is first-class</h1>')
})

test('/тест雨 (test non ascii route)', async () => {
const { html } = await nuxt.server.renderRoute('/тест雨')
expect(html).toMatch('Hello unicode')
})

// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()
Expand Down
7 changes: 7 additions & 0 deletions test/unit/spa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ describe('spa', () => {
expect(html).toMatch('error handler triggered: asyncData error!')
})

test('/тест雨 (test non ascii route)', async () => {
const { html } = await renderRoute('/тест雨')
expect(html).toMatch('Hello unicode SPA!')
expect(consola.log).not.toHaveBeenCalledWith('created')
expect(consola.log).toHaveBeenCalledWith('mounted')
consola.log.mockClear()
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()
Expand Down