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

Fix for issue #195 #202

Merged
merged 1 commit into from Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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