Skip to content

Commit

Permalink
Ensure optional value normalizing is correct for index (vercel#33547)
Browse files Browse the repository at this point in the history
This fixes a case where optional catch-all route values aren't normalized to an array properly when the `index` value is passed. An additional test case has been added to prevent regressing on this. 

x-ref: [slack thread](https://vercel.slack.com/archives/CGU8HUTUH/p1642791113093400)

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
  • Loading branch information
ijjk authored Jan 21, 2022
1 parent 2a349c7 commit f5fb181
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/next/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ export default abstract class Server {
}

if (params) {
params = utils.normalizeDynamicRouteParams(params).params
if (!paramsResult.hasValidParams) {
params = utils.normalizeDynamicRouteParams(params).params
}

matchedPathname = utils.interpolateDynamicPath(
matchedPathname,
Expand Down
17 changes: 17 additions & 0 deletions test/production/required-server-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,23 @@ describe('should set-up next', () => {
expect(json.url).toBe('/api/optional?another=value')
})

it('should normalize index optional values correctly for API page', async () => {
const res = await fetchViaHTTP(
appPort,
'/api/optional/index',
{ rest: 'index', another: 'value' },
{
headers: {
'x-matched-path': '/api/optional/[[...rest]]',
},
}
)

const json = await res.json()
expect(json.query).toEqual({ another: 'value', rest: ['index'] })
expect(json.url).toBe('/api/optional/index?another=value')
})

it('should match the index page correctly', async () => {
const res = await fetchViaHTTP(appPort, '/', undefined, {
headers: {
Expand Down

0 comments on commit f5fb181

Please sign in to comment.