Skip to content

Commit

Permalink
Ensure error is shown correctly for empty headers field (#28430)
Browse files Browse the repository at this point in the history
* Ensure error is shown correctly for empty headers field

* Apply suggestions from code review

Co-authored-by: Steven <steven@ceriously.com>

Co-authored-by: Steven <steven@ceriously.com>
  • Loading branch information
ijjk and styfle committed Aug 25, 2021
1 parent cb6290a commit 706547e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/next/lib/load-custom-routes.ts
Expand Up @@ -108,6 +108,8 @@ function checkHeader(route: Header): string[] {

if (!Array.isArray(route.headers)) {
invalidParts.push('`headers` field must be an array')
} else if (route.headers.length === 0) {
invalidParts.push('`headers` field cannot be empty')
} else {
for (const header of route.headers) {
if (!header || typeof header !== 'object') {
Expand Down
17 changes: 17 additions & 0 deletions test/integration/invalid-custom-routes/test/index.test.js
Expand Up @@ -25,6 +25,23 @@ const writeConfig = async (routes, type = 'redirects') => {
let getStderr

const runTests = () => {
it('should error when empty headers array is present on header item', async () => {
await writeConfig(
[
{
source: `/:path*`,
headers: [],
},
],
'headers'
)
const stderr = await getStderr()

expect(stderr).toContain(
'`headers` field cannot be empty for route {"source":"/:path*"'
)
})

it('should error when source and destination length is exceeded', async () => {
await writeConfig(
[
Expand Down

0 comments on commit 706547e

Please sign in to comment.