Commit 0b4552a8 by Torkel Ödegaard

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

parent 2345b41a
......@@ -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);
}
......
......@@ -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: []
},
......
......@@ -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() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment