Skip to content

Commit

Permalink
Fixes grbsk#76 by safely handing missing expiries in localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
grbsk committed Apr 29, 2015
1 parent b0a5f66 commit e7272c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/idle/idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
function getExpiry() {
var obj = LocalStorage.get('expiry');

return new Date(obj.time);
return obj && obj.time ? new Date(obj.time) : null;
}

function setExpiry(date) {
Expand Down Expand Up @@ -148,7 +148,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
},
isExpired: function() {
var expiry = getExpiry();
return expiry && expiry <= this._getNow();
return expiry !== null && expiry <= this._getNow();
},
running: function() {
return state.running;
Expand Down
4 changes: 4 additions & 0 deletions src/idle/idle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ describe('ngIdle', function() {
expect(Idle.isExpired()).toBe(true);
});

it ('isExpired() should return false if there is no expiry yet', function() {
expect(Idle.isExpired()).toBe(false);
});

it ('interrupt() should broadcast $timeout if running and past expiry', function() {
spyOn($rootScope, '$broadcast');

Expand Down

0 comments on commit e7272c0

Please sign in to comment.