Skip to content

Commit 706547e

Browse files
ijjkstyfle
andauthored
Ensure error is shown correctly for empty headers field (#28430)
* 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>
1 parent cb6290a commit 706547e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/next/lib/load-custom-routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ function checkHeader(route: Header): string[] {
108108

109109
if (!Array.isArray(route.headers)) {
110110
invalidParts.push('`headers` field must be an array')
111+
} else if (route.headers.length === 0) {
112+
invalidParts.push('`headers` field cannot be empty')
111113
} else {
112114
for (const header of route.headers) {
113115
if (!header || typeof header !== 'object') {

test/integration/invalid-custom-routes/test/index.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ const writeConfig = async (routes, type = 'redirects') => {
2525
let getStderr
2626

2727
const runTests = () => {
28+
it('should error when empty headers array is present on header item', async () => {
29+
await writeConfig(
30+
[
31+
{
32+
source: `/:path*`,
33+
headers: [],
34+
},
35+
],
36+
'headers'
37+
)
38+
const stderr = await getStderr()
39+
40+
expect(stderr).toContain(
41+
'`headers` field cannot be empty for route {"source":"/:path*"'
42+
)
43+
})
44+
2845
it('should error when source and destination length is exceeded', async () => {
2946
await writeConfig(
3047
[

0 commit comments

Comments
 (0)