Skip to content

Commit

Permalink
Fix detection of numeric value when parsing short options (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Oct 15, 2022
1 parent 980d7ac commit 7564f07
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions test/short.js
Expand Up @@ -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' ]),
Expand Down

0 comments on commit 7564f07

Please sign in to comment.