Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
e037c229
Unverified
Commit
e037c229
authored
Mar 02, 2021
by
JJ Kasper
Committed by
GitHub
Mar 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure optional params are normalized in minimal mode (#22676)
parent
a107dcb7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
98 additions
and
4 deletions
+98
-4
next-server.ts
packages/next/next-server/server/next-server.ts
+4
-4
[[...rest]].js
...n/required-server-files/pages/api/optional/[[...rest]].js
+7
-0
[[...rest]].js
...n/required-server-files/pages/optional-ssg/[[...rest]].js
+20
-0
[[...rest]].js
...n/required-server-files/pages/optional-ssp/[[...rest]].js
+13
-0
index.test.js
test/integration/required-server-files/test/index.test.js
+54
-0
No files found.
packages/next/next-server/server/next-server.ts
View file @
e037c229
...
@@ -369,10 +369,9 @@ export default class Server {
...
@@ -369,10 +369,9 @@ export default class Server {
// interpolate dynamic params and normalize URL if needed
// interpolate dynamic params and normalize URL if needed
if
(
pageIsDynamic
)
{
if
(
pageIsDynamic
)
{
let
params
:
ParsedUrlQuery
|
false
=
{}
let
params
:
ParsedUrlQuery
|
false
=
{}
const
paramsResult
=
utils
.
normalizeDynamicRouteParams
({
...
parsedUrl
.
query
,
Object
.
assign
(
parsedUrl
.
query
,
query
)
...
query
,
const
paramsResult
=
utils
.
normalizeDynamicRouteParams
(
parsedUrl
.
query
)
})
if
(
paramsResult
.
hasValidParams
)
{
if
(
paramsResult
.
hasValidParams
)
{
params
=
paramsResult
.
params
params
=
paramsResult
.
params
...
@@ -407,6 +406,7 @@ export default class Server {
...
@@ -407,6 +406,7 @@ export default class Server {
pathname
:
matchedPathname
,
pathname
:
matchedPathname
,
})
})
}
}
Object
.
assign
(
parsedUrl
.
query
,
params
)
Object
.
assign
(
parsedUrl
.
query
,
params
)
utils
.
normalizeVercelUrl
(
req
,
true
)
utils
.
normalizeVercelUrl
(
req
,
true
)
}
}
...
...
test/integration/required-server-files/pages/api/optional/[[...rest]].js
0 → 100644
View file @
e037c229
export
default
(
req
,
res
)
=>
{
console
.
log
(
req
.
url
,
'query'
,
req
.
query
)
res
.
json
({
url
:
req
.
url
,
query
:
req
.
query
,
})
}
test/integration/required-server-files/pages/optional-ssg/[[...rest]].js
0 → 100644
View file @
e037c229
export
const
getStaticProps
=
({
params
})
=>
{
return
{
props
:
{
random
:
Math
.
random
(),
params
:
params
||
null
,
},
revalidate
:
1
,
}
}
export
const
getStaticPaths
=
()
=>
{
return
{
paths
:
[],
fallback
:
true
,
}
}
export
default
function
Page
(
props
)
{
return
<
p
id
=
"props"
>
{
JSON
.
stringify
(
props
)}
<
/p
>
}
test/integration/required-server-files/pages/optional-ssp/[[...rest]].js
0 → 100644
View file @
e037c229
export
const
getServerSideProps
=
({
query
,
params
})
=>
{
return
{
props
:
{
random
:
Math
.
random
(),
query
:
query
,
params
:
params
||
null
,
},
}
}
export
default
function
Page
(
props
)
{
return
<
p
id
=
"props"
>
{
JSON
.
stringify
(
props
)}
<
/p
>
}
test/integration/required-server-files/test/index.test.js
View file @
e037c229
...
@@ -448,4 +448,58 @@ describe('Required Server Files', () => {
...
@@ -448,4 +448,58 @@ describe('Required Server Files', () => {
expect
(
errors
.
length
).
toBe
(
1
)
expect
(
errors
.
length
).
toBe
(
1
)
expect
(
errors
[
0
].
message
).
toContain
(
'gsp hit an oops'
)
expect
(
errors
[
0
].
message
).
toContain
(
'gsp hit an oops'
)
})
})
it
(
'should normalize optional values correctly for SSP page'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/optional-ssp'
,
{
rest
:
''
,
another
:
'value'
},
{
headers
:
{
'x-matched-path'
:
'/optional-ssp/[[...rest]]'
,
},
}
)
const
html
=
await
res
.
text
()
const
$
=
cheerio
.
load
(
html
)
const
props
=
JSON
.
parse
(
$
(
'#props'
).
text
())
expect
(
props
.
params
).
toEqual
({})
expect
(
props
.
query
).
toEqual
({
another
:
'value'
})
})
it
(
'should normalize optional values correctly for SSG page'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/optional-ssg'
,
{
rest
:
''
,
another
:
'value'
},
{
headers
:
{
'x-matched-path'
:
'/optional-ssg/[[...rest]]'
,
},
}
)
const
html
=
await
res
.
text
()
const
$
=
cheerio
.
load
(
html
)
const
props
=
JSON
.
parse
(
$
(
'#props'
).
text
())
expect
(
props
.
params
).
toEqual
({})
})
it
(
'should normalize optional values correctly for API page'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/api/optional'
,
{
rest
:
''
,
another
:
'value'
},
{
headers
:
{
'x-matched-path'
:
'/api/optional/[[...rest]]'
,
},
}
)
const
json
=
await
res
.
json
()
expect
(
json
.
query
).
toEqual
({
another
:
'value'
})
expect
(
json
.
url
).
toBe
(
'/api/optional?another=value'
)
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment