Skip to content

Commit e2dbb25

Browse files
shadowspawnljharb
authored andcommitted
Fix detection of numeric value when parsing short options (#2)
1 parent 62fde7d commit e2dbb25

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ module.exports = function (args, opts) {
195195

196196
if (
197197
(/[A-Za-z]/).test(letters[j])
198-
&& (/-?\d+(\.\d*)?(e-?\d+)?$/).test(next)
198+
&& (/^-?\d+(\.\d*)?(e-?\d+)?$/).test(next)
199199
) {
200200
setArg(letters[j], next, arg);
201201
broken = true;

test/short.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ test('numeric short args', function (t) {
1212
);
1313
});
1414

15+
test('partial numeric short args', function (t) {
16+
t.plan(1);
17+
t.deepEqual(parse(['-n1b3']), { n: true, 1: true, b: 3, _: [] });
18+
});
19+
1520
test('short', function (t) {
1621
t.deepEqual(
1722
parse(['-b']),

0 commit comments

Comments
 (0)