Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure error is shown correctly for empty headers field #28430

Merged
merged 3 commits into from Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 can not be empty')
ijjk marked this conversation as resolved.
Show resolved Hide resolved
} 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 can not be empty for route {"source":"/:path*"'
ijjk marked this conversation as resolved.
Show resolved Hide resolved
)
})

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