Skip to content

Commit

Permalink
[Fix] Fix handling of short option with non-trivial equals
Browse files Browse the repository at this point in the history
Rework -a=bc handling

Fixes #5.
  • Loading branch information
shadowspawn authored and ljharb committed Oct 16, 2022
1 parent 3124ed3 commit 9c7dc85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ module.exports = function (args, opts) {
continue;
}

if ((/[A-Za-z]/).test(letters[j]) && (/[=]/).test(next)) {
setArg(letters[j], next.split('=')[1], arg);
if ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {
setArg(letters[j], next.slice(1), arg);
broken = true;
break;
}
Expand Down
14 changes: 14 additions & 0 deletions test/kv_short.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ test('multi short -k=v', function (t) {
var argv = parse(['-a=whatever', '-b=robots']);
t.deepEqual(argv, { a: 'whatever', b: 'robots', _: [] });
});

test('short with embedded equals -k=a=b', function (t) {
t.plan(1);

var argv = parse(['-k=a=b']);
t.deepEqual(argv, { k: 'a=b', _: [] });
});

test('short with later equals like -ab=c', function (t) {
t.plan(1);

var argv = parse(['-ab=c']);
t.deepEqual(argv, { a: true, b: 'c', _: [] });
});

0 comments on commit 9c7dc85

Please sign in to comment.