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 authored and ljharb committed Oct 15, 2022
1 parent 62fde7d commit e2dbb25
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 @@ -195,7 +195,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;
Expand Down
5 changes: 5 additions & 0 deletions test/short.js
Expand Up @@ -12,6 +12,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 e2dbb25

Please sign in to comment.