From d1add60365fe2340b750b1f7a254b83bea34e52d Mon Sep 17 00:00:00 2001 From: YuLe Date: Wed, 6 Feb 2019 09:22:06 +0800 Subject: [PATCH] Update regexp for `10-.5` is invalid input (#117) --- index.js | 2 +- tests.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8b3455a..c4498bc 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ function parse(str) { if (str.length > 100) { return; } - var match = /^((?:\d+)?-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( + var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( str ); if (!match) { diff --git a/tests.js b/tests.js index 6a44931..1d0d663 100644 --- a/tests.js +++ b/tests.js @@ -55,6 +55,7 @@ describe('ms(string)', function() { it('should return NaN if invalid', function() { expect(isNaN(ms('☃'))).to.be(true); + expect(isNaN(ms('10-.5'))).to.be(true); }); it('should be case-insensitive', function() {