fix(nuxt): encode location header in navigateTo (#26712)

This commit is contained in:
Julien Huang 2024-04-10 09:03:25 +02:00 committed by GitHub
parent a7425d30a7
commit 30e27f48d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -169,7 +169,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
nuxtApp.ssrContext!._renderResponse = { nuxtApp.ssrContext!._renderResponse = {
statusCode: sanitizeStatusCode(options?.redirectCode || 302, 302), statusCode: sanitizeStatusCode(options?.redirectCode || 302, 302),
body: `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head></html>`, body: `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head></html>`,
headers: { location }, headers: { location: encodeURI(location) },
} }
return response return response
} }

View File

@ -900,6 +900,12 @@ describe('navigate', () => {
expect(status).toEqual(404) expect(status).toEqual(404)
}) })
it('expect to redirect with encoding', async () => {
const { status } = await fetch('/redirect-with-encode', { redirect: 'manual' })
expect(status).toEqual(302)
})
}) })
describe('preserves current instance', () => { describe('preserves current instance', () => {

View File

@ -0,0 +1,9 @@
<template>
<div>
oh no !
</div>
</template>
<script setup lang="ts">
await navigateTo('/cœur')
</script>