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

Returned null in case of empty cookie value #196

Merged
merged 7 commits into from Feb 16, 2021
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);
vsin12 marked this conversation as resolved.
Show resolved Hide resolved

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looked at this in context, and I think this is fine. Will discuss today.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comment below; I think we may want an Error here.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually return an error, we are invoking the callback with a Null here. Should we invoke the CB with an Error()?

assert(cookies == undefined);
}
}
}
})
.export(module);