Skip to content

Commit

Permalink
Merge pull request #202 from salesforce/issue_195
Browse files Browse the repository at this point in the history
Fix for issue #195
  • Loading branch information
medelibero-sfdc committed Sep 21, 2020
2 parents 5655a73 + 395dfb7 commit 0ccbbec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,11 @@ All notable changes to this project will be documented in this file.
### Minor Changes
- Added parameter checking to setCookie so as to error out when no URL was passed in

## X.Y.Z

### Minor Changes
- Added loose mode to the serialized options. Now a serialized cookie jar with loose mode enabled will honor that flag when deserialized.

## 4.0.0

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

// CookieJar configuration:
rejectPublicSuffixes: !!this.rejectPublicSuffixes,
enableLooseMode: !!this.enableLooseMode,

// this gets filled from getAllCookies:
cookies: []
Expand Down Expand Up @@ -1615,7 +1616,10 @@ class CookieJar {
serialized = strOrObj;
}

const jar = new CookieJar(store, serialized.rejectPublicSuffixes);
const jar = new CookieJar(store, {
rejectPublicSuffixes: serialized.rejectPublicSuffixes,
looseMode: serialized.enableLooseMode
});
jar._importCookies(serialized, err => {
if (err) {
return cb(err);
Expand All @@ -1627,7 +1631,10 @@ class CookieJar {
static deserializeSync(strOrObj, store) {
const serialized =
typeof strOrObj === "string" ? JSON.parse(strOrObj) : strOrObj;
const jar = new CookieJar(store, serialized.rejectPublicSuffixes);
const jar = new CookieJar(store, {
rejectPublicSuffixes: serialized.rejectPublicSuffixes,
looseMode: serialized.enableLooseMode
});

// catch this mistake early:
if (!jar.store.synchronous) {
Expand Down
13 changes: 13 additions & 0 deletions test/cookie_jar_test.js
Expand Up @@ -543,6 +543,19 @@ vows
assert.strictEqual(cookies[0].key, "");
assert.strictEqual(cookies[0].value, "FooBar");
}
},
"Loose Mode Cloned": {
topic: function() {
const cj = new CookieJar(null, { looseMode: true });
return CookieJar.fromJSON(cj.toJSON());
},
"parses loose cookies from serialized cookie jar": function(cj) {
cj.setCookieSync("FooBar", "http://www.foonet.net", {});
const cookies = cj.getCookiesSync("http://www.foonet.net");
assert.strictEqual(cookies.length, 1);
assert.strictEqual(cookies[0].key, "");
assert.strictEqual(cookies[0].value, "FooBar");
}
}
})
.addBatch({
Expand Down

0 comments on commit 0ccbbec

Please sign in to comment.