Skip to content

Commit f82c61d

Browse files
ronaganonrig
authored andcommitted
fix: ensure header value is a string (nodejs#1899)
* fix: ensure header value is a string * fixup * fixup * fixup * fixup
1 parent d78fd2d commit f82c61d

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

lib/core/request.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,13 @@ class Request {
279279
}
280280

281281
function processHeaderValue (key, val) {
282-
if (val && (typeof val === 'object' && !Array.isArray(val))) {
282+
if (val && typeof val === 'object') {
283283
throw new InvalidArgumentError(`invalid ${key} header`)
284-
} else if (headerCharRegex.exec(val) !== null) {
284+
}
285+
286+
val = val != null ? `${val}` : ''
287+
288+
if (headerCharRegex.exec(val) !== null) {
285289
throw new InvalidArgumentError(`invalid ${key} header`)
286290
}
287291

test/client-dispatch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ test('basic dispatch get', (t) => {
9494
t.equal(`localhost:${server.address().port}`, req.headers.host)
9595
t.equal(undefined, req.headers.foo)
9696
t.equal('bar', req.headers.bar)
97-
t.equal('null', req.headers.baz)
97+
t.equal('', req.headers.baz)
9898
t.equal(undefined, req.headers['content-length'])
9999
res.end('hello')
100100
})

0 commit comments

Comments
 (0)