Skip to content

Commit

Permalink
fix: ensure header value is a string (nodejs#1899)
Browse files Browse the repository at this point in the history
* fix: ensure header value is a string

* fixup

* fixup

* fixup

* fixup
  • Loading branch information
ronag authored and anonrig committed Apr 4, 2023
1 parent d78fd2d commit f82c61d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}

Expand Down
2 changes: 1 addition & 1 deletion test/client-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down

0 comments on commit f82c61d

Please sign in to comment.