Skip to content

Commit 9c7dc85

Browse files
shadowspawnljharb
authored andcommitted
[Fix] Fix handling of short option with non-trivial equals
Rework -a=bc handling Fixes #5.
1 parent 3124ed3 commit 9c7dc85

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ module.exports = function (args, opts) {
189189
continue;
190190
}
191191

192-
if ((/[A-Za-z]/).test(letters[j]) && (/[=]/).test(next)) {
193-
setArg(letters[j], next.split('=')[1], arg);
192+
if ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {
193+
setArg(letters[j], next.slice(1), arg);
194194
broken = true;
195195
break;
196196
}

test/kv_short.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ test('multi short -k=v', function (t) {
1616
var argv = parse(['-a=whatever', '-b=robots']);
1717
t.deepEqual(argv, { a: 'whatever', b: 'robots', _: [] });
1818
});
19+
20+
test('short with embedded equals -k=a=b', function (t) {
21+
t.plan(1);
22+
23+
var argv = parse(['-k=a=b']);
24+
t.deepEqual(argv, { k: 'a=b', _: [] });
25+
});
26+
27+
test('short with later equals like -ab=c', function (t) {
28+
t.plan(1);
29+
30+
var argv = parse(['-ab=c']);
31+
t.deepEqual(argv, { a: true, b: 'c', _: [] });
32+
});

0 commit comments

Comments
 (0)