Unverified Commit dcb7e681 authored by onFire(Abhi)'s avatar onFire(Abhi) Committed by GitHub

fix redirect to url with semicolon (#65165)

Closes https://github.com/vercel/next.js/issues/64904

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent ad0c5bb0
......@@ -106,7 +106,10 @@ export function isRedirectError<U extends string>(
return false
}
const [errorCode, type, destination, status] = error.digest.split(';', 4)
const digest = error.digest.split(';')
const [errorCode, type] = digest
const destination = digest.slice(2, -2).join(';')
const status = digest.at(-2)
const statusCode = Number(status)
......@@ -134,7 +137,7 @@ export function getURLFromRedirectError(error: unknown): string | null {
// Slices off the beginning of the digest that contains the code and the
// separating ';'.
return error.digest.split(';', 3)[2]
return error.digest.split(';').slice(2, -2).join(';')
}
export function getRedirectTypeFromError<U extends string>(
......@@ -154,5 +157,5 @@ export function getRedirectStatusCodeFromError<U extends string>(
throw new Error('Not a redirect error')
}
return Number(error.digest.split(';', 4)[3])
return Number(error.digest.split(';').at(-2))
}
import { redirect } from 'next/navigation'
export const dynamic = 'force-dynamic'
export default function Page() {
return redirect('/?a=b;c')
}
......@@ -24,6 +24,17 @@ describe('app dir - navigation', () => {
expect(url.searchParams.toString()).toMatchInlineSnapshot(`"a=b&c=d"`)
})
it('should set query with semicolon correctly', async () => {
const browser = await next.browser('/redirect/semicolon')
await retry(() =>
expect(browser.elementById('query').text()).resolves.toEqual('a=b%3Bc')
)
const url = new URL(await browser.url())
expect(url.searchParams.toString()).toBe('a=b%3Bc')
})
it('should handle unicode search params', async () => {
const requests: Array<{
pathname: string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment