Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle empty query param issue in url redirects #68039 #68157

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ export function prepareDestination(args: {
let escapedDestination = args.destination

for (const param of Object.keys({ ...args.params, ...query })) {
escapedDestination = escapeSegment(escapedDestination, param)
escapedDestination = param
? escapeSegment(escapedDestination, param)
: escapedDestination
}

const parsedDestination = parseUrl(escapedDestination)
Expand Down
1 change: 1 addition & 0 deletions test/e2e/app-dir/app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ describe('app dir - basic', () => {
{ pathname: '/blog/old-post' },
{ pathname: '/redirect-3/some' },
{ pathname: '/redirect-4' },
{ pathname: '/redirect-4/?q=1&=' },
])(
'should match redirects in pages correctly $path',
async ({ pathname }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,14 @@ describe('redirects and rewrites', () => {
const url = new URL(await browser.url())
expect(url.pathname).toEndWith('-after/thing')
})
it('should redirect from next.config.js correctly with empty query params', async () => {
const browser = await next.browser('/?q=1&=')
await browser
.elementById(`${testType}-config-redirect`)
.click()
.waitForElementByCss('.page_config-redirect-after')
const url = new URL(await browser.url())
expect(url.pathname).toEndWith('-after')
})
})
})
Loading