Skip to content

Commit

Permalink
Merge pull request #196 from vsin12/checkForEmptyCookie
Browse files Browse the repository at this point in the history
Returned null in case of empty cookie value
  • Loading branch information
medelibero-sfdc committed Feb 16, 2021
2 parents 5ae97c6 + 7e2c51b commit 65e9a52
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/cookie.js
Expand Up @@ -1100,8 +1100,13 @@ class CookieJar {
cb = options;
options = {};
}

validators.validate(validators.isFunction(cb), cb);

if(!validators.isNonEmptyString(cookie) && !validators.isObject(cookie) && ( cookie instanceof String && cookie.length == 0)) {
return cb(null);
}

const host = canonicalDomain(context.hostname);
const loose = options.loose || this.enableLooseMode;

Expand Down
17 changes: 17 additions & 0 deletions test/cookie_jar_test.js
Expand Up @@ -699,4 +699,21 @@ vows
}
}
})
.addBatch({
"Issue #197 - CookieJar().setCookie crashes when empty cookie is passed": {
"with missing parameters": {
topic: function() {
const jar = new tough.CookieJar();
jar.setCookie(
'',
"https://google.com",
this.callback
);
},
"results in a error being returned because of missing parameters": function(err, cookies) {
assert(cookies == undefined);
}
}
}
})
.export(module);

0 comments on commit 65e9a52

Please sign in to comment.