☕️ Classic, reliable, trusted test framework for Node.js and the browser
fix: only reject positional args that are entirely numeric (#6222)
Lazizbek Ergashev163377915b2a
diff --git a/lib/utils.cjs b/lib/utils.cjsindex dbfd97f9..7ec9f415 100644--- a/lib/utils.cjs+++ b/lib/utils.cjs@@ -732,7 +732,7 @@ exports.breakCircularDeps = (inputObj) => {* Checks if provided input can be parsed as a JavaScript Number.*/exports.isNumeric = (input) => {- return !isNaN(parseFloat(input));+ return String(input).trim() !== "" && !isNaN(Number(input));};/**diff --git a/test/node-unit/cli/options.spec.js b/test/node-unit/cli/options.spec.jsindex 3e93f312..db0abf56 100644--- a/test/node-unit/cli/options.spec.js+++ b/test/node-unit/cli/options.spec.js@@ -843,6 +843,10 @@ describe("options", function () {it("does not throw error if numeric value is passed to an array flag", function () {expect(() => loadOptions(`--spec ${numericArg}`), "not to throw");});++ it("does not throw error if a positional file name begins with a number", function () {+ expect(() => loadOptions("1-spec.js"), "not to throw");+ });});describe("when parsing throws a non-Mocha error", function () {diff --git a/test/node-unit/utils.spec.cjs b/test/node-unit/utils.spec.cjsindex 6c0c01cb..7937b742 100644--- a/test/node-unit/utils.spec.cjs+++ b/test/node-unit/utils.spec.cjs@@ -55,6 +55,9 @@ describe("utils", function () {it("returns false for a string that cannot be parsed as a number", function () {expect(utils.isNumeric("foo"), "to equal", false);});+ it("returns false for a string that only begins with a number", function () {+ expect(utils.isNumeric("1-spec.js"), "to equal", false);+ });it("returns false for empty string", function () {expect(utils.isNumeric(""), "to equal", false);});