Skip to content

Commit

Permalink
Merge pull request #25 from keithamus/fix-24-add-cookieaccessinfo-all
Browse files Browse the repository at this point in the history
feat: add CookieAccessInfo.All sentinel
  • Loading branch information
bmeck authored Jul 12, 2016
2 parents 3c3d43c + a0a4cbd commit c9c3a0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cookiejar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
return new CookieAccessInfo(domain, path, secure, script);
}
CookieAccessInfo.All = Object.freeze(Object.create(null));
exports.CookieAccessInfo = CookieAccessInfo;

function Cookie(cookiestr, request_domain, request_path) {
Expand Down Expand Up @@ -118,6 +119,9 @@
};

Cookie.prototype.matches = function matches(access_info) {
if (access_info === CookieAccessInfo.All) {
return true;
}
if (this.noscript && access_info.script ||
this.secure && !access_info.secure ||
!this.collidesWith(access_info)) {
Expand Down
5 changes: 5 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ assert.equal(cookie.path, "/accounts");
test_jar.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
var cookies = test_jar.getCookies(CookieAccessInfo("test.com"));
assert.equal(cookies.length, 3);

test_jar.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
var cookie = test_jar.getCookie('sub', CookieAccessInfo.All);
assert(cookie);
assert.equal(cookie.name, 'sub');

0 comments on commit c9c3a0c

Please sign in to comment.