Unverified Commit d66445f8 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure optional params are normalized correctly in minimal mode (#36513)

Follow-up for https://github.com/vercel/next.js/pull/36463 this fixes an issue with optional catch-all params not being normalized correctly which was caught by the runtimes tests. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent e9b423b3
...@@ -530,7 +530,7 @@ export default abstract class Server { ...@@ -530,7 +530,7 @@ export default abstract class Server {
parsedUrl.query.__nextLocale = opts.locale parsedUrl.query.__nextLocale = opts.locale
} }
} else { } else {
params = utils.dynamicRouteMatcher!(matchedPathnameNoExt) params = utils.dynamicRouteMatcher!(matchedPathnameNoExt) || {}
} }
if (params) { if (params) {
......
...@@ -804,6 +804,86 @@ describe('should set-up next', () => { ...@@ -804,6 +804,86 @@ describe('should set-up next', () => {
expect(props.params).toEqual({}) expect(props.params).toEqual({})
}) })
it('should normalize optional revalidations correctly for SSG page', async () => {
const reqs = [
{
path: `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
headers: {
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
},
},
{
path: `/_next/data/${next.buildId}/optional-ssg.json`,
headers: {
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
},
},
{
path: `/_next/data/${next.buildId}/optional-ssg.json`,
headers: {
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg.json`,
},
},
{
path: `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
headers: {
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
},
query: { rest: '' },
},
{
path: `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
headers: {
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
'x-now-route-matches': '1=',
},
},
{
path: `/_next/data/${next.buildId}/optional-ssg/.json`,
headers: {
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
'x-now-route-matches': '',
'x-vercel-id': 'cle1::',
},
},
{
path: `/optional-ssg/[[...rest]]`,
headers: {
'x-matched-path': `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
'x-now-route-matches': '',
'x-vercel-id': 'cle1::',
},
},
{
path: `/_next/data/${next.buildId}/optional-ssg/[[...rest]].json`,
headers: {
'x-matched-path': `/optional-ssg/[[...rest]]`,
'x-now-route-matches': '',
'x-vercel-id': 'cle1::',
},
},
]
for (const req of reqs) {
console.error('checking', req)
const res = await fetchViaHTTP(appPort, req.path, req.query, {
headers: req.headers,
})
const content = await res.text()
let props
try {
const data = JSON.parse(content)
props = data.pageProps
} catch (_) {
props = JSON.parse(cheerio.load(content)('#__NEXT_DATA__').text()).props
.pageProps
}
expect(props.params).toEqual({})
}
})
it('should normalize optional values correctly for SSG page with encoded slash', async () => { it('should normalize optional values correctly for SSG page with encoded slash', async () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
appPort, appPort,
......
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