Skip to content

Commit

Permalink
Fix handling of short with non-trivial equals
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Oct 16, 2022
1 parent 980d7ac commit 1a9a793
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 @@ -149,8 +149,8 @@ module.exports = function (args, opts) {
continue;
}

if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
setArg(letters[j], next.split('=')[1], arg);
if (j === 0 && /[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 @@ -14,3 +14,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 is not kv like -ab=c' , function (t) {
t.plan(1);

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

0 comments on commit 1a9a793

Please sign in to comment.