fix(vue-app): prevent redirection loop with uri encoded path (#8280)

This commit is contained in:
Daniel Roe 2020-11-04 13:35:12 +00:00 committed by GitHub
parent 011b3b4491
commit e14b7201b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -50,7 +50,7 @@ const createNext = ssrContext => (opts) => {
opts.path = urlJoin(routerBase, opts.path)
}
// Avoid loop redirect
if (opts.path === ssrContext.url) {
if (decodeURIComponent(opts.path) === ssrContext.url) {
ssrContext.redirected = false
return
}

View File

@ -319,6 +319,11 @@ describe('basic browser', () => {
page.close()
})
test('/redirection/no loop', async () => {
const page = await browser.page(url('/redirection/no loop'))
expect(await page.$text('h1')).toContain('Redirected page')
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()

View File

@ -0,0 +1,18 @@
<template>
<h1>
Redirected page
</h1>
</template>
<script>
export default {
asyncData ({ redirect, route }) {
if (process.server) {
// Redirect to the same route
redirect(route)
}
return {}
}
}
</script>