Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2c2b658

Browse filesBrowse files
jinwoogibfahn
authored andcommitted
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: #16452 PR-URL: #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>
1 parent 568d614 commit 2c2b658
Copy full SHA for 2c2b658

File tree

Expand file treeCollapse file tree

2 files changed

+14
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/http2/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/util.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,14 @@ function mapToHeaders(map,
403403
if (typeof key === 'symbol' || value === undefined || !key)
404404
continue;
405405
key = String(key).toLowerCase();
406-
const isArray = Array.isArray(value);
406+
let isArray = Array.isArray(value);
407407
if (isArray) {
408408
switch (value.length) {
409409
case 0:
410410
continue;
411411
case 1:
412412
value = String(value[0]);
413+
isArray = false;
413414
break;
414415
default:
415416
if (kSingleValueHeaders.has(key))
Collapse file

‎test/parallel/test-http2-util-headers-list.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-util-headers-list.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ const {
154154
);
155155
}
156156

157+
{
158+
// Arrays containing a single set-cookie value are handled correctly
159+
// (https://github.com/nodejs/node/issues/16452)
160+
const headers = {
161+
'set-cookie': 'foo=bar'
162+
};
163+
assert.deepStrictEqual(
164+
mapToHeaders(headers),
165+
[ [ 'set-cookie', 'foo=bar', '' ].join('\0'), 1 ]
166+
);
167+
}
168+
157169
// The following are not allowed to have multiple values
158170
[
159171
HTTP2_HEADER_STATUS,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.