Skip to content

Commit a0a4cbd

Browse files
committed
feat: add CookieAccessInfo.All sentinel
This allows for fetching cookies with any access info, useful for tests. Fixes #24
1 parent 3c3d43c commit a0a4cbd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

cookiejar.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
}
1313
return new CookieAccessInfo(domain, path, secure, script);
1414
}
15+
CookieAccessInfo.All = Object.freeze(Object.create(null));
1516
exports.CookieAccessInfo = CookieAccessInfo;
1617

1718
function Cookie(cookiestr, request_domain, request_path) {
@@ -118,6 +119,9 @@
118119
};
119120

120121
Cookie.prototype.matches = function matches(access_info) {
122+
if (access_info === CookieAccessInfo.All) {
123+
return true;
124+
}
121125
if (this.noscript && access_info.script ||
122126
this.secure && !access_info.secure ||
123127
!this.collidesWith(access_info)) {

tests/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ assert.equal(cookie.path, "/accounts");
8080
test_jar.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
8181
var cookies = test_jar.getCookies(CookieAccessInfo("test.com"));
8282
assert.equal(cookies.length, 3);
83+
84+
test_jar.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
85+
var cookie = test_jar.getCookie('sub', CookieAccessInfo.All);
86+
assert(cookie);
87+
assert.equal(cookie.name, 'sub');

0 commit comments

Comments
 (0)