Unverified Commit 706547e0 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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: 's avatarSteven <steven@ceriously.com>
Co-authored-by: 's avatarSteven <steven@ceriously.com>
parent cb6290ad
...@@ -108,6 +108,8 @@ function checkHeader(route: Header): string[] { ...@@ -108,6 +108,8 @@ function checkHeader(route: Header): string[] {
if (!Array.isArray(route.headers)) { if (!Array.isArray(route.headers)) {
invalidParts.push('`headers` field must be an array') invalidParts.push('`headers` field must be an array')
} else if (route.headers.length === 0) {
invalidParts.push('`headers` field cannot be empty')
} else { } else {
for (const header of route.headers) { for (const header of route.headers) {
if (!header || typeof header !== 'object') { if (!header || typeof header !== 'object') {
......
...@@ -25,6 +25,23 @@ const writeConfig = async (routes, type = 'redirects') => { ...@@ -25,6 +25,23 @@ const writeConfig = async (routes, type = 'redirects') => {
let getStderr let getStderr
const runTests = () => { 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 () => { it('should error when source and destination length is exceeded', async () => {
await writeConfig( await writeConfig(
[ [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment