Unverified Commit 7a733dfd authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

fix edge route catch-all param parsing (#59343)

### What?
Visiting an edge catch-all route incorrectly truncates multiple
parameters

### Why?
The params are currently coerced into a `ParsedURLQuery`-like format by
calling `Object.fromEntries` on `searchParams`, but this doesn't
consider multiple param values assigned to the same key

### How?
Rather than use `fromEntries`, this uses an existing util to get the
path into `ParsedURLQuery` format.

Closes NEXT-1814
Fixes #59333
parent 61b825be
...@@ -13,6 +13,7 @@ import { RouteMatcher } from '../future/route-matchers/route-matcher' ...@@ -13,6 +13,7 @@ import { RouteMatcher } from '../future/route-matchers/route-matcher'
import type { NextFetchEvent } from './spec-extension/fetch-event' import type { NextFetchEvent } from './spec-extension/fetch-event'
import { internal_getCurrentFunctionWaitUntil } from './internal-edge-wait-until' import { internal_getCurrentFunctionWaitUntil } from './internal-edge-wait-until'
import { getUtils } from '../server-utils' import { getUtils } from '../server-utils'
import { searchParamsToUrlQuery } from '../../shared/lib/router/utils/querystring'
type WrapOptions = Partial<Pick<AdapterOptions, 'page'>> type WrapOptions = Partial<Pick<AdapterOptions, 'page'>>
...@@ -78,7 +79,7 @@ export class EdgeRouteModuleWrapper { ...@@ -78,7 +79,7 @@ export class EdgeRouteModuleWrapper {
}) })
const { params } = utils.normalizeDynamicRouteParams( const { params } = utils.normalizeDynamicRouteParams(
Object.fromEntries(request.nextUrl.searchParams) searchParamsToUrlQuery(request.nextUrl.searchParams)
) )
const prerenderManifest: PrerenderManifest | undefined = const prerenderManifest: PrerenderManifest | undefined =
......
import { NextRequest, NextResponse } from 'next/server'
export const runtime = 'edge'
type Context = {
params: {
slug: string[]
}
}
export const GET = async (req: NextRequest, { params }: Context) => {
return NextResponse.json(params)
}
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'edge-route-catchall',
{
files: __dirname,
},
({ next }) => {
it('should correctly normalize edge route catch-all with a single param', async () => {
const result = await next.fetch('/edge/one')
expect(await result.text()).toBe(JSON.stringify({ slug: ['one'] }))
})
it('should correctly normalize edge route catch-all with multiple params', async () => {
const result = await next.fetch('/edge/one/two/three')
expect(await result.text()).toBe(
JSON.stringify({ slug: ['one', 'two', 'three'] })
)
})
}
)
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
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