Skip to content

Commit

Permalink
Merge pull request #34 from danielmcq/master
Browse files Browse the repository at this point in the history
Fix issue when parsing invalid cookies
  • Loading branch information
andyburke committed May 30, 2018
2 parents 207de77 + 1730d38 commit f6e3097
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cookiejar.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,22 @@
if (this instanceof Cookie) {
var parts = str.split(";").filter(function (value) {
return !!value;
}),
pair = parts[0].match(/([^=]+)=([\s\S]*)/),
key = pair[1],
value = pair[2],
i;
});
var i;

var pair = parts[0].match(/([^=]+)=([\s\S]*)/);
if (!pair) {
console.warn("Invalid cookie header encountered. Header: '"+str+"'");
return;
}

var key = pair[1];
var value = pair[2];
if ( typeof key !== 'string' || key.length === 0 || typeof value !== 'string' ) {
console.warn("Unable to extract values from cookie header. Cookie: '"+str+"'");
return;
}

this.name = key;
this.value = value;

Expand Down

0 comments on commit f6e3097

Please sign in to comment.