fix(timerange): fix handling of invalid dates in from/to url parameters, fixes #3345

This commit is contained in:
Torkel Ödegaard 2015-12-04 10:32:23 +01:00
parent 2345b41a74
commit 0b4552a8e7
3 changed files with 13 additions and 3 deletions

View File

@ -21,6 +21,7 @@ define([
this._initTimeFromUrl();
this._parseTime();
console.log(dashboard.time);
if(this.dashboard.refresh) {
this.setAutoRefresh(this.dashboard.refresh);
@ -47,8 +48,9 @@ define([
if (value.length === 15) {
return moment.utc(value, 'YYYYMMDDTHHmmss');
}
var epoch = parseInt(value);
if (!_.isNaN(epoch)) {
if (!isNaN(value)) {
var epoch = parseInt(value);
return moment(epoch);
}

View File

@ -15,7 +15,7 @@ define([],
rows: [],
pulldowns: [ { type: 'templating' }, { type: 'annotations' } ],
nav: [ { type: 'timepicker' } ],
time: {from: '1h', to: 'now'},
time: {from: 'now-6h', to: 'now'},
templating: {
list: []
},

View File

@ -75,6 +75,14 @@ define([
expect(time.to.valueOf()).to.equal(1410337665699);
});
it('should handle bad dates', function() {
ctx.$routeParams.from = '20151126T00010%3C%2Fp%3E%3Cspan%20class';
ctx.$routeParams.to = 'now';
_dashboard.time.from = 'now-6h';
ctx.service.init(_dashboard);
expect(ctx.service.time.from).to.equal('now-6h');
expect(ctx.service.time.to).to.equal('now');
});
});
describe('setTime', function() {