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
b747f7b2
Commit
b747f7b2
authored
Jan 23, 2020
by
Luis Alvarez D
Committed by
JJ Kasper
Jan 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for invalid objects in rewrites/redirects/headers (#10238)
parent
f4a5b612
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
check-custom-routes.ts
packages/next/lib/check-custom-routes.ts
+12
-0
index.test.js
test/integration/invalid-custom-routes/test/index.test.js
+44
-1
No files found.
packages/next/lib/check-custom-routes.ts
View file @
b747f7b2
...
...
@@ -95,6 +95,18 @@ export default function checkCustomRoutes(
}
for
(
const
route
of
routes
)
{
if
(
!
route
||
typeof
route
!==
'object'
)
{
console
.
error
(
`The route
${
JSON
.
stringify
(
route
)}
is not a valid object with \`source\` and \`
${
type
===
'header'
?
'headers'
:
'destination'
}
\``
)
numInvalidRoutes
++
continue
}
const
keys
=
Object
.
keys
(
route
)
const
invalidKeys
=
keys
.
filter
(
key
=>
!
allowedKeys
.
has
(
key
))
const
invalidParts
:
string
[]
=
[]
...
...
test/integration/invalid-custom-routes/test/index.test.js
View file @
b747f7b2
...
...
@@ -59,6 +59,9 @@ const runTests = () => {
destination
:
'/another'
,
permanent
:
'yes'
,
},
// invalid objects
null
,
'string'
,
],
'redirects'
)
...
...
@@ -68,6 +71,10 @@ const runTests = () => {
`\`destination\` is missing for route {"source":"/hello","permanent":false}`
)
expect
(
stderr
).
toContain
(
`\`destination\` is missing for route {"source":"/hello","permanent":false}`
)
expect
(
stderr
).
toContain
(
`\`source\` is not a string for route {"source":123,"destination":"/another","permanent":false}`
)
...
...
@@ -85,8 +92,21 @@ const runTests = () => {
)
expect
(
stderr
).
toContain
(
'Valid redirect statusCode values are 301, 302, 303, 307, 308'
`\`permanent\` is not set to \`true\` or \`false\` for route {"source":"/hello","destination":"/another","permanent":"yes"}`
)
expect
(
stderr
).
toContain
(
`\`permanent\` is not set to \`true\` or \`false\` for route {"source":"/hello","destination":"/another","permanent":"yes"}`
)
expect
(
stderr
).
toContain
(
`The route null is not a valid object with \`source\` and \`destination\``
)
expect
(
stderr
).
toContain
(
`The route "string" is not a valid object with \`source\` and \`destination\``
)
expect
(
stderr
).
toContain
(
'Invalid redirects found'
)
})
...
...
@@ -122,6 +142,9 @@ const runTests = () => {
source
:
'/feedback/(?!general)'
,
destination
:
'/feedback/general'
,
},
// invalid objects
null
,
'string'
,
],
'rewrites'
)
...
...
@@ -150,6 +173,15 @@ const runTests = () => {
expect
(
stderr
).
toContain
(
`Error parsing \`/feedback/(?!general)\` https://err.sh/zeit/next.js/invalid-route-source`
)
expect
(
stderr
).
toContain
(
`The route null is not a valid object with \`source\` and \`destination\``
)
expect
(
stderr
).
toContain
(
`The route "string" is not a valid object with \`source\` and \`destination\``
)
expect
(
stderr
).
toContain
(
`Reason: Pattern cannot start with "?" at 11`
)
expect
(
stderr
).
toContain
(
`/feedback/(?!general)`
)
...
...
@@ -220,6 +252,9 @@ const runTests = () => {
},
],
},
// invalid objects
null
,
'string'
,
],
'headers'
)
...
...
@@ -245,6 +280,14 @@ const runTests = () => {
'invalid field: destination for route {"source":"/again","destination":"/another","headers":[{"key":"x-first","value":"idk"}]}'
)
expect
(
stderr
).
toContain
(
`The route null is not a valid object with \`source\` and \`headers\``
)
expect
(
stderr
).
toContain
(
`The route "string" is not a valid object with \`source\` and \`headers\``
)
expect
(
stderr
).
not
.
toContain
(
'/valid-header'
)
})
...
...
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