Skip to content

Commit d79cc2c

Browse files
authored
Merge pull request #82 from spokodev/fix/hunt
fix: don't throw when a set-cookie string has no name-value-pair
2 parents 39b7c1c + 971fe3f commit d79cc2c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/set-cookie.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ function parseString(setCookieValue, options) {
2121
var parts = setCookieValue.split(";").filter(isNonEmptyString);
2222

2323
var nameValuePairStr = parts.shift();
24+
if (!nameValuePairStr) {
25+
return null;
26+
}
2427
var parsed = parseNameValuePair(nameValuePairStr);
2528
var name = parsed.name;
2629
var value = parsed.value;

test/set-cookie-parser.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ describe("set-cookie-parser", function () {
233233
assert.deepEqual(actual, expected);
234234
});
235235

236+
it("should ignore a set-cookie string with no name-value-pair instead of throwing", function () {
237+
assert.deepEqual(parseSetCookie(";"), []);
238+
assert.deepEqual(parseSetCookie(" ; "), []);
239+
assert.deepEqual(parseSetCookie([";", "foo=bar"]), [
240+
{ name: "foo", value: "bar" },
241+
]);
242+
assert.deepEqual(parseSetCookie(";", { map: true }), {});
243+
});
244+
236245
it("should skip cookies that could pollute the object prototype", function () {
237246
var actual = parseSetCookie("__proto__=test;");
238247
var expected = [];

0 commit comments

Comments
 (0)