From 7564f07ae643f30da1ef5c310e92987cafda0080 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sun, 16 Oct 2022 11:16:01 +1300 Subject: [PATCH] Fix detection of numeric value when parsing short options (#2) --- index.js | 2 +- test/short.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d9c3eb7..8770876 100644 --- a/index.js +++ b/index.js @@ -156,7 +156,7 @@ module.exports = function (args, opts) { } if (/[A-Za-z]/.test(letters[j]) - && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) { + && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) { setArg(letters[j], next, arg); broken = true; break; diff --git a/test/short.js b/test/short.js index d513a1c..5c9fe51 100644 --- a/test/short.js +++ b/test/short.js @@ -10,6 +10,11 @@ test('numeric short args', function (t) { ); }); +test('partial numeric short args', function (t) { + t.plan(1); + t.deepEqual(parse([ '-n1b3' ]), { n: true, 1: true, b: 3, _: [], }); +}); + test('short', function (t) { t.deepEqual( parse([ '-b' ]),