diff --git a/lib/persistent_session.js b/lib/persistent_session.js index cabcfa6..7c45edc 100644 --- a/lib/persistent_session.js +++ b/lib/persistent_session.js @@ -394,8 +394,10 @@ PersistentSession.prototype.clear = function _psClear(key, list) { self.set(akey, undefined, false, false); changed(self._dict.keyDeps[akey]); - changed(self._dict.keyValueDeps[akey][value]); - changed(self._dict.keyValueDeps[akey]['undefined']); + if (self._dict.keyValueDeps[akey]) { + changed(self._dict.keyValueDeps[akey][value]); + changed(self._dict.keyValueDeps[akey]['undefined']); + } delete self._dict.keys[akey]; // remove the key }); diff --git a/tests/client/persistent_session.js b/tests/client/persistent_session.js index fa93f23..dc4fdcb 100644 --- a/tests/client/persistent_session.js +++ b/tests/client/persistent_session.js @@ -36,6 +36,19 @@ Tinytest.add("clear all keys", function(test) { test.equal(undefined, result); }); +Tinytest.add("skip undefined keys", function(test) { + var TestSession = new PersistentSession(Random.id()); + test.equal(_.keys(TestSession._dict.keys).length, 0); + + TestSession.set(undefined, 'woo'); + test.equal(_.keys(TestSession._dict.keys).length, 1); + + TestSession.clear(); + + test.equal(_.keys(TestSession._dict.keys).length, 0); + +}); + Tinytest.add("clear single key", function(test) { var TestSession = new PersistentSession(Random.id());