Skip to content

Commit f6e3097

Browse files
authored
Merge pull request #34 from danielmcq/master
Fix issue when parsing invalid cookies
2 parents 207de77 + 1730d38 commit f6e3097

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

cookiejar.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,22 @@
6767
if (this instanceof Cookie) {
6868
var parts = str.split(";").filter(function (value) {
6969
return !!value;
70-
}),
71-
pair = parts[0].match(/([^=]+)=([\s\S]*)/),
72-
key = pair[1],
73-
value = pair[2],
74-
i;
70+
});
71+
var i;
72+
73+
var pair = parts[0].match(/([^=]+)=([\s\S]*)/);
74+
if (!pair) {
75+
console.warn("Invalid cookie header encountered. Header: '"+str+"'");
76+
return;
77+
}
78+
79+
var key = pair[1];
80+
var value = pair[2];
81+
if ( typeof key !== 'string' || key.length === 0 || typeof value !== 'string' ) {
82+
console.warn("Unable to extract values from cookie header. Cookie: '"+str+"'");
83+
return;
84+
}
85+
7586
this.name = key;
7687
this.value = value;
7788

0 commit comments

Comments
 (0)