From f82c61dbe6b1a442237e54bb6f8c10e76fd8dee8 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 6 Feb 2023 06:59:41 +0100 Subject: [PATCH] fix: ensure header value is a string (#1899) * fix: ensure header value is a string * fixup * fixup * fixup * fixup --- lib/core/request.js | 8 ++++++-- test/client-dispatch.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/core/request.js b/lib/core/request.js index e476fc1bcc1..7271bc64f24 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -279,9 +279,13 @@ class Request { } function processHeaderValue (key, val) { - if (val && (typeof val === 'object' && !Array.isArray(val))) { + if (val && typeof val === 'object') { throw new InvalidArgumentError(`invalid ${key} header`) - } else if (headerCharRegex.exec(val) !== null) { + } + + val = val != null ? `${val}` : '' + + if (headerCharRegex.exec(val) !== null) { throw new InvalidArgumentError(`invalid ${key} header`) } diff --git a/test/client-dispatch.js b/test/client-dispatch.js index 9e59fdb2fb5..2196e5d53f5 100644 --- a/test/client-dispatch.js +++ b/test/client-dispatch.js @@ -94,7 +94,7 @@ test('basic dispatch get', (t) => { t.equal(`localhost:${server.address().port}`, req.headers.host) t.equal(undefined, req.headers.foo) t.equal('bar', req.headers.bar) - t.equal('null', req.headers.baz) + t.equal('', req.headers.baz) t.equal(undefined, req.headers['content-length']) res.end('hello') })