Skip to content

Commit

Permalink
Changed this.idx initialization (PR salesforce#283) (lib/memstore.js)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharduany committed May 14, 2024
1 parent 7c1fdf1 commit 5b036c5
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/memstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var util = require('util');

function MemoryCookieStore() {
Store.call(this);
this.idx = {};
this.idx = Object.create(null);
}
util.inherits(MemoryCookieStore, Store);
exports.MemoryCookieStore = MemoryCookieStore;
Expand Down Expand Up @@ -86,18 +86,18 @@ MemoryCookieStore.prototype.findCookies = function(domain, path, cb) {

} else {
pathMatcher = function matchRFC(domainIndex) {
//NOTE: we should use path-match algorithm from S5.1.4 here
//(see : https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/canonical_cookie.cc#L299)
Object.keys(domainIndex).forEach(function (cookiePath) {
if (pathMatch(path, cookiePath)) {
var pathIndex = domainIndex[cookiePath];

for (var key in pathIndex) {
results.push(pathIndex[key]);
}
}
});
};
//NOTE: we should use path-match algorithm from S5.1.4 here
//(see : https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/canonical_cookie.cc#L299)
Object.keys(domainIndex).forEach(function (cookiePath) {
if (pathMatch(path, cookiePath)) {
var pathIndex = domainIndex[cookiePath];

for (var key in pathIndex) {
results.push(pathIndex[key]);
}
}
});
};
}

var domains = permuteDomain(domain) || [domain];
Expand All @@ -115,10 +115,10 @@ MemoryCookieStore.prototype.findCookies = function(domain, path, cb) {

MemoryCookieStore.prototype.putCookie = function(cookie, cb) {
if (!this.idx[cookie.domain]) {
this.idx[cookie.domain] = {};
this.idx[cookie.domain] = Object.create(null);
}
if (!this.idx[cookie.domain][cookie.path]) {
this.idx[cookie.domain][cookie.path] = {};
this.idx[cookie.domain][cookie.path] = Object.create(null);
}
this.idx[cookie.domain][cookie.path][cookie.key] = cookie;
cb(null);
Expand Down Expand Up @@ -150,7 +150,7 @@ MemoryCookieStore.prototype.removeCookies = function(domain, path, cb) {
};

MemoryCookieStore.prototype.removeAllCookies = function(cb) {
this.idx = {};
this.idx = Object.create(null);
return cb(null);
}

Expand Down

0 comments on commit 5b036c5

Please sign in to comment.