http2: fix mapToHeaders() with single string value
This is for issue 16452. When 'set-cookie' header is set with an array that has only one string value, it's split into its individual characters. Fix by resetting `isArray` to false when the value is converted from an array to a string. Fixes: https://github.com/nodejs/node/issues/16452 PR-URL: https://github.com/nodejs/node/pull/16458 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
parent
0a03e350fb
commit
b61a08ca2d
@ -403,13 +403,14 @@ function mapToHeaders(map,
|
|||||||
if (typeof key === 'symbol' || value === undefined || !key)
|
if (typeof key === 'symbol' || value === undefined || !key)
|
||||||
continue;
|
continue;
|
||||||
key = String(key).toLowerCase();
|
key = String(key).toLowerCase();
|
||||||
const isArray = Array.isArray(value);
|
let isArray = Array.isArray(value);
|
||||||
if (isArray) {
|
if (isArray) {
|
||||||
switch (value.length) {
|
switch (value.length) {
|
||||||
case 0:
|
case 0:
|
||||||
continue;
|
continue;
|
||||||
case 1:
|
case 1:
|
||||||
value = String(value[0]);
|
value = String(value[0]);
|
||||||
|
isArray = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (kSingleValueHeaders.has(key))
|
if (kSingleValueHeaders.has(key))
|
||||||
|
@ -154,6 +154,18 @@ const {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Arrays containing a single set-cookie value are handled correctly
|
||||||
|
// (https://github.com/nodejs/node/issues/16452)
|
||||||
|
const headers = {
|
||||||
|
'set-cookie': 'foo=bar'
|
||||||
|
};
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
mapToHeaders(headers),
|
||||||
|
[ [ 'set-cookie', 'foo=bar', '' ].join('\0'), 1 ]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// The following are not allowed to have multiple values
|
// The following are not allowed to have multiple values
|
||||||
[
|
[
|
||||||
HTTP2_HEADER_STATUS,
|
HTTP2_HEADER_STATUS,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user