Skip to content

Commit 39b2be4

Browse files
author
amine
committed
Better document cookie addition
Update README file and tests file to better document the cookie addition process, that is the pure cookie appending
1 parent f7c331b commit 39b2be4

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

readme.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
#CookieJar
1+
# CookieJar
22

33
Simple robust cookie library
44

5-
##Exports
5+
## Exports
66

7-
###CookieAccessInfo(domain,path,secure,script)
7+
### CookieAccessInfo(domain,path,secure,script)
88

99
class to determine matching qualities of a cookie
1010

11-
#####Properties
11+
##### Properties
1212

1313
* String domain - domain to match
1414
* String path - path to match
1515
* Boolean secure - access is secure (ssl generally)
1616
* Boolean script - access is from a script
1717

1818

19-
###Cookie(cookiestr_or_cookie, request_domain, request_path)
19+
### Cookie(cookiestr_or_cookie, request_domain, request_path)
2020

2121
turns input into a Cookie (singleton if given a Cookie)
2222
the `request_domain` argument is used to default the domain if it is not explicit in the cookie string
2323
the `request_path` argument is used to set the path if it is not explicit in a cookie String.
2424

2525
explicit domains/paths will cascade, implied domains/paths must *exactly* match (see http://en.wikipedia.org/wiki/HTTP_cookie#Domain_and_Pat)
2626

27-
#####Properties
27+
##### Properties
2828

2929
* String name - name of the cookie
3030
* String value - string associated with the cookie
@@ -36,7 +36,7 @@ Simple robust cookie library
3636
* Boolean secure - should it only be transmitted over secure means
3737
* Number expiration_date - number of millis since 1970 at which this should be removed
3838

39-
#####Methods
39+
##### Methods
4040

4141
* String toString() - the __set-cookie:__ string for this cookie
4242
* String toValueString() - the __cookie:__ string for this cookie
@@ -45,13 +45,13 @@ Simple robust cookie library
4545
* Boolean collidesWith(cookie) - returns true if the cookies cannot exist in the same space (domain and path match)
4646

4747

48-
###CookieJar()
48+
### CookieJar()
4949

5050
class to hold numerous cookies from multiple domains correctly
5151

52-
#####Methods
52+
##### Methods
5353

54-
* Cookie setCookie(cookie, request_domain, request_path) - add a cookie to the jar
55-
* Cookie[] setCookies(cookiestr_or_list, request_domain, request_path) - add a large number of cookies to the jar
54+
* Cookie setCookie(cookie, request_domain, request_path) - modify (or add if not already-existing) a cookie to the jar
55+
* Cookie[] setCookies(cookiestr_or_list, request_domain, request_path) - modify (or add if not already-existing) a large number of cookies to the jar
5656
* Cookie getCookie(cookie_name,access_info) - get a cookie with the name and access_info matching
5757
* Cookie[] getCookies(access_info) - grab all cookies matching this access_info

tests/test.js

100755100644
Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,21 @@ assert.equal(String(test_jar.getCookies(CookieAccessInfo("test.com","/"))), "a=1
4343
cookie=Cookie("a=1;domain=test.com;path=/;HttpOnly");
4444
assert.ok(cookie.noscript, "HttpOnly flag parsing failed\n" + cookie.toString());
4545

46-
var test_jar = CookieJar();
47-
test_jar.setCookies([
48-
"a=1;domain=.test.com;path=/"
49-
, "a=1;domain=.test.com;path=/"
50-
, "a=2;domain=.test.com;path=/"
51-
, "b=3;domain=.test.com;path=/"]);
52-
var cookies=test_jar.getCookies(CookieAccessInfo("test.com","/"))
53-
assert.equal(cookies.length, 2);
54-
assert.equal(cookies[0].value, 2);
46+
var test_jar2 = CookieJar();
47+
test_jar2.setCookies([
48+
"a=1;domain=.test.com;path=/"
49+
, "a=1;domain=.test.com;path=/"
50+
, "a=2;domain=.test.com;path=/"
51+
, "b=3;domain=.test.com;path=/"]);
52+
var cookies2=test_jar2.getCookies(CookieAccessInfo("test.com","/"))
53+
assert.equal(cookies2.length, 2);
54+
assert.equal(cookies2[0].value, 2);
55+
56+
// Test pure appending
57+
test_jar2.setCookie("d=4;domain=.test.com;path=/");
58+
cookies2=test_jar2.getCookies(CookieAccessInfo("test.com","/"))
59+
assert.equal(cookies2.length, 3);
60+
assert.equal(cookies2[2].value, 4);
5561

5662
// Test Ignore Trailing Semicolons (Github Issue #6)
5763
var cookie = new Cookie("a=1;domain=.test.com;path=/;;;;");
@@ -62,26 +68,26 @@ assert.equal(cookie.path, "/");
6268
assert.deepEqual(cookie, new Cookie("a=1;domain=.test.com;path=/"));
6369

6470
// Test request_path and request_domain
65-
test_jar.setCookie(new Cookie("sub=4;path=/", "test.com"));
66-
var cookie = test_jar.getCookie("sub", CookieAccessInfo("sub.test.com", "/"));
71+
test_jar2.setCookie(new Cookie("sub=4;path=/", "test.com"));
72+
var cookie = test_jar2.getCookie("sub", CookieAccessInfo("sub.test.com", "/"));
6773
assert.equal(cookie, undefined);
6874

69-
var cookie = test_jar.getCookie("sub", CookieAccessInfo("test.com", "/"));
75+
var cookie = test_jar2.getCookie("sub", CookieAccessInfo("test.com", "/"));
7076
assert.equal(cookie.name, "sub");
7177
assert.equal(cookie.domain, "test.com");
7278

73-
test_jar.setCookie(new Cookie("sub=4;path=/accounts", "test.com", "/accounts"));
74-
var cookie = test_jar.getCookie("sub", CookieAccessInfo("test.com", "/foo"));
79+
test_jar2.setCookie(new Cookie("sub=4;path=/accounts", "test.com", "/accounts"));
80+
var cookie = test_jar2.getCookie("sub", CookieAccessInfo("test.com", "/foo"));
7581
assert.equal(cookie, undefined);
7682

77-
var cookie = test_jar.getCookie("sub", CookieAccessInfo("test.com", "/accounts"));
83+
var cookie = test_jar2.getCookie("sub", CookieAccessInfo("test.com", "/accounts"));
7884
assert.equal(cookie.path, "/accounts");
7985

80-
test_jar.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
81-
var cookies = test_jar.getCookies(CookieAccessInfo("test.com"));
82-
assert.equal(cookies.length, 3);
86+
test_jar2.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
87+
var cookies = test_jar2.getCookies(CookieAccessInfo("test.com"));
88+
assert.equal(cookies.length, 4);
8389

84-
test_jar.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
85-
var cookie = test_jar.getCookie('sub', CookieAccessInfo.All);
90+
test_jar2.setCookie(new Cookie("sub=5;path=/", "test.com", "/accounts"));
91+
var cookie = test_jar2.getCookie('sub', CookieAccessInfo.All);
8692
assert(cookie);
8793
assert.equal(cookie.name, 'sub');

0 commit comments

Comments
 (0)