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

This commit is contained in:
Julien Huang 2024-05-20 22:02:46 +02:00 committed by GitHub
parent 341e3d060a
commit a618a5c1d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View File

@ -169,8 +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>`,
// do not encode as this would break some modules and some environments headers: { location: encodeURI(location) },
headers: { location },
} }
return response return response
} }

View File

@ -972,6 +972,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>