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
97587eb8
Unverified
Commit
97587eb8
authored
May 18, 2020
by
JJ Kasper
Committed by
GitHub
May 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct multi-match behavior for queries and header values (#13017)
parent
dd264f58
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
2 deletions
+57
-2
next-server.ts
packages/next/next-server/server/next-server.ts
+5
-1
router.ts
packages/next/next-server/server/router.ts
+4
-1
next.config.js
test/integration/custom-routes/next.config.js
+13
-0
index.test.js
test/integration/custom-routes/test/index.test.js
+35
-0
No files found.
packages/next/next-server/server/next-server.ts
View file @
97587eb8
...
@@ -482,7 +482,11 @@ export default class Server {
...
@@ -482,7 +482,11 @@ export default class Server {
!
parsedDestination
.
pathname
||
!
parsedDestination
.
pathname
||
!
parsedDestination
.
pathname
.
startsWith
(
'/'
)
!
parsedDestination
.
pathname
.
startsWith
(
'/'
)
)
{
)
{
return
compilePathToRegex
(
value
,
{
validate
:
false
})(
params
)
// the value needs to start with a forward-slash to be compiled
// correctly
return
compilePathToRegex
(
`/
${
value
}
`
,
{
validate
:
false
})(
params
).
substr
(
1
)
}
}
return
formatUrl
(
parsedDestination
)
return
formatUrl
(
parsedDestination
)
}
}
...
...
packages/next/next-server/server/router.ts
View file @
97587eb8
...
@@ -58,8 +58,11 @@ export const prepareDestination = (
...
@@ -58,8 +58,11 @@ export const prepareDestination = (
for
(
const
[
key
,
strOrArray
]
of
Object
.
entries
(
destQuery
))
{
for
(
const
[
key
,
strOrArray
]
of
Object
.
entries
(
destQuery
))
{
let
value
=
Array
.
isArray
(
strOrArray
)
?
strOrArray
[
0
]
:
strOrArray
let
value
=
Array
.
isArray
(
strOrArray
)
?
strOrArray
[
0
]
:
strOrArray
if
(
value
)
{
if
(
value
)
{
// the value needs to start with a forward-slash to be compiled
// correctly
value
=
`/
${
value
}
`
const
queryCompiler
=
compilePathToRegex
(
value
,
{
validate
:
false
})
const
queryCompiler
=
compilePathToRegex
(
value
,
{
validate
:
false
})
value
=
queryCompiler
(
params
)
value
=
queryCompiler
(
params
)
.
substr
(
1
)
}
}
destQuery
[
key
]
=
value
destQuery
[
key
]
=
value
}
}
...
...
test/integration/custom-routes/next.config.js
View file @
97587eb8
...
@@ -91,6 +91,10 @@ module.exports = {
...
@@ -91,6 +91,10 @@ module.exports = {
source
:
'/catchall-rewrite/:path*'
,
source
:
'/catchall-rewrite/:path*'
,
destination
:
'/with-params'
,
destination
:
'/with-params'
,
},
},
{
source
:
'/catchall-query/:path*'
,
destination
:
'/with-params?another=:path*'
,
},
]
]
},
},
async
redirects
()
{
async
redirects
()
{
...
@@ -283,6 +287,15 @@ module.exports = {
...
@@ -283,6 +287,15 @@ module.exports = {
},
},
],
],
},
},
{
source
:
'/catchall-header/:path*'
,
headers
:
[
{
key
:
'x-value'
,
value
:
':path*'
,
},
],
},
]
]
},
},
},
},
...
...
test/integration/custom-routes/test/index.test.js
View file @
97587eb8
...
@@ -178,6 +178,22 @@ const runTests = (isDev = false) => {
...
@@ -178,6 +178,22 @@ const runTests = (isDev = false) => {
})
})
})
})
it
(
'should have correct query for catchall rewrite'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/catchall-query/hello/world?a=b'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
query
).
toEqual
({
a
:
'b'
,
another
:
'hello/world'
,
path
:
[
'hello'
,
'world'
],
})
})
it
(
'should have correct query for catchall rewrite'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/catchall-header/hello/world?a=b'
)
const
headerValue
=
res
.
headers
.
get
(
'x-value'
)
expect
(
headerValue
).
toBe
(
'hello/world'
)
})
it
(
'should allow params in query for redirect'
,
async
()
=>
{
it
(
'should allow params in query for redirect'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
const
res
=
await
fetchViaHTTP
(
appPort
,
appPort
,
...
@@ -716,6 +732,18 @@ const runTests = (isDev = false) => {
...
@@ -716,6 +732,18 @@ const runTests = (isDev = false) => {
regex
:
normalizeRegEx
(
'^
\\
/named-pattern(?:
\\
/(.*))$'
),
regex
:
normalizeRegEx
(
'^
\\
/named-pattern(?:
\\
/(.*))$'
),
source
:
'/named-pattern/:path(.*)'
,
source
:
'/named-pattern/:path(.*)'
,
},
},
{
headers
:
[
{
key
:
'x-value'
,
value
:
':path*'
,
},
],
regex
:
normalizeRegEx
(
'^
\\
/catchall-header(?:
\\
/((?:[^
\\
/]+?)(?:
\\
/(?:[^
\\
/]+?))*))?$'
),
source
:
'/catchall-header/:path*'
,
},
],
],
rewrites
:
[
rewrites
:
[
{
{
...
@@ -840,6 +868,13 @@ const runTests = (isDev = false) => {
...
@@ -840,6 +868,13 @@ const runTests = (isDev = false) => {
),
),
source
:
'/catchall-rewrite/:path*'
,
source
:
'/catchall-rewrite/:path*'
,
},
},
{
destination
:
'/with-params?another=:path*'
,
regex
:
normalizeRegEx
(
'^
\\
/catchall-query(?:
\\
/((?:[^
\\
/]+?)(?:
\\
/(?:[^
\\
/]+?))*))?$'
),
source
:
'/catchall-query/:path*'
,
},
],
],
dynamicRoutes
:
[
dynamicRoutes
:
[
{
{
...
...
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