From 9091a53b75d388a0eb70c30986c672d5b5d405c5 Mon Sep 17 00:00:00 2001 From: David Vo Date: Tue, 25 Jun 2024 14:17:35 +1000 Subject: [PATCH] fix: allow empty output from header command --- src/headers.test.ts | 2 +- src/headers.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/headers.test.ts b/src/headers.test.ts index 1fa5f759..6c8a9b6d 100644 --- a/src/headers.test.ts +++ b/src/headers.test.ts @@ -17,6 +17,7 @@ it("should return no headers", async () => { await expect(getHeaders("", "command", logger)).resolves.toStrictEqual({}) await expect(getHeaders("localhost", " ", logger)).resolves.toStrictEqual({}) await expect(getHeaders(" ", "command", logger)).resolves.toStrictEqual({}) + await expect(getHeaders("localhost", "printf ''", logger)).resolves.toStrictEqual({}) }) it("should return headers", async () => { @@ -43,7 +44,6 @@ it("should error on malformed or empty lines", async () => { await expect(getHeaders("localhost", "printf ' =foo'", logger)).rejects.toMatch(/Malformed/) await expect(getHeaders("localhost", "printf 'foo =bar'", logger)).rejects.toMatch(/Malformed/) await expect(getHeaders("localhost", "printf 'foo foo=bar'", logger)).rejects.toMatch(/Malformed/) - await expect(getHeaders("localhost", "printf ''", logger)).rejects.toMatch(/Malformed/) }) it("should have access to environment variables", async () => { diff --git a/src/headers.ts b/src/headers.ts index 259ad4a4..e870a557 100644 --- a/src/headers.ts +++ b/src/headers.ts @@ -59,6 +59,10 @@ export async function getHeaders( } throw new Error(`Header command exited unexpectedly: ${error}`) } + if (!result.stdout) { + // Allow no output for parity with the Coder CLI. + return headers + } const lines = result.stdout.replace(/\r?\n$/, "").split(/\r?\n/) for (let i = 0; i < lines.length; ++i) { const [key, value] = lines[i].split(/=(.*)/)