From 5b036c51a519cfc27b89087bf7772ed174952425 Mon Sep 17 00:00:00 2001 From: Shahar Duany Date: Tue, 14 May 2024 12:44:03 +0300 Subject: [PATCH] Changed this.idx initialization (PR #283) (lib/memstore.js) --- lib/memstore.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/memstore.js b/lib/memstore.js index d2b915c9..ffa203f7 100644 --- a/lib/memstore.js +++ b/lib/memstore.js @@ -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; @@ -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]; @@ -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); @@ -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); }