Skip to content

Commit

Permalink
fix(nuxt): encode location header in navigateTo (#26712)
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-julien committed Apr 10, 2024
1 parent a7425d3 commit 30e27f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/composables/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
nuxtApp.ssrContext!._renderResponse = {
statusCode: sanitizeStatusCode(options?.redirectCode || 302, 302),
body: `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head></html>`,
headers: { location },
headers: { location: encodeURI(location) },
}
return response
}
Expand Down
6 changes: 6 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,12 @@ describe('navigate', () => {

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', () => {
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/basic/pages/redirect-with-encode.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<div>
oh no !
</div>
</template>

<script setup lang="ts">
await navigateTo('/cœur')
</script>

0 comments on commit 30e27f4

Please sign in to comment.