Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing param validation issue145 #193

Merged
merged 9 commits into from Jul 24, 2020
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## 4.X.X

### Mintor Changes
awaterma marked this conversation as resolved.
Show resolved Hide resolved
- Added in parameter checking to setCookie to error out when no URL was passed in
awaterma marked this conversation as resolved.
Show resolved Hide resolved

## 4.0.0

### Breaking Changes (Major Version)
Expand Down
7 changes: 7 additions & 0 deletions lib/cookie.js
Expand Up @@ -1077,6 +1077,13 @@ class CookieJar {

setCookie(cookie, url, options, cb) {
let err;

if (typeof(url) === "function") {
cb = url
err = new Error("No URL was specified");
return cb(err);
}
awaterma marked this conversation as resolved.
Show resolved Hide resolved

const context = getCookieContext(url);
if (typeof options === "function") {
cb = options;
Expand Down
17 changes: 17 additions & 0 deletions test/cookie_jar_test.js
Expand Up @@ -669,4 +669,21 @@ vows
}
}
})
.addBatch({
"Issue #145 - Missing parameter validation on setCookie function causes TypeError": {
"with missing parameters": {
topic: function() {
const jar = new tough.CookieJar();
jar.setCookie(
new String("x=y; Domain=example.com; Path=/"),
this.callback
);
},
"results in a error being returned because of missing parameters": function(err, cookies) {
assert(err != null);
assert.equal(err.message, "No URL was specified");
}
}
}
})
.export(module);