From ae506f1b0aaed943ca4ca21e48a1c9b7618d0846 Mon Sep 17 00:00:00 2001 From: yuler Date: Sun, 16 Dec 2018 09:58:17 +0800 Subject: [PATCH] Update regexp for `10-.5` is invalid input --- index.js | 2 +- tests.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a1d2ea4..a2d1969 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 9427390..9141689 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() {