Fix date math parser to not use hardcoded length (#17751)

* Fix date math parser to not use hardcoded length

* Add test
This commit is contained in:
Lukas Olson 2018-04-18 14:08:28 -07:00 committed by GitHub
parent b994ab3f56
commit 2ec9956885
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -82,7 +82,7 @@ function parseDateMath(mathString, time, roundUp) {
const numFrom = i;
while (!isNaN(mathString.charAt(i))) {
i++;
if (i > 10) return;
if (i >= len) return;
}
num = parseInt(mathString.substring(numFrom, i), 10);
}

View file

@ -322,6 +322,10 @@ describe('dateMath', function() {
.valueOf();
expect(val).to.eql(anchored.startOf('s').valueOf());
});
it('should parse long expressions', () => {
expect(dateMath.parse('now-1d/d+8h+50m')).to.be.ok();
});
});
describe('used momentjs instance', function() {