Skip to content

Commit

Permalink
Fix issue with trying to evaluate unparsed EJSON value
Browse files Browse the repository at this point in the history
  • Loading branch information
rgould committed Mar 17, 2015
1 parent ec98ed4 commit bc34fc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Master [changes](https://github.com/okgrow/meteor-persistent-session/compare/v0.3.0...master)

* Fix issue with trying to evaluate unparsed EJSON value

### [0.3.0](https://github.com/okgrow/meteor-persistent-session/compare/v0.2.2...v0.3.0)

* Changed `default_method` to "temporary", fixes #15 ([pull request #16](https://github.com/okgrow/meteor-persistent-session/pull/16) by [aramk](https://github.com/aramk))
Expand Down
10 changes: 7 additions & 3 deletions lib/persistent_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@ Session.store = function _psStore(type, key, value) {
Session.old_get = Session.get;
Session.get = function _psGet(key) {
var val = this.old_get(key);
var psVal = Session.store('get', key);
var psVal;
var unparsedPsVal = Session.store('get', key);
if (unparsedPsVal !== undefined) {
psVal = EJSON.parse(Session.store('get', key));
}
/*
* We can't do `return psVal || val;` here, as when psVal = undefined and
* val = 0, it will return undefined, even though 0 is the correct value.
*/
if (psVal === undefined) {
if (psVal === undefined || psVal === null) {
return val;
}
return EJSON.parse(psVal);
return psVal;
};

// === SET ===
Expand Down

0 comments on commit bc34fc0

Please sign in to comment.