From 9c7dc85ab9e835ec5ae1c2590d1fb792d54fb626 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sun, 16 Oct 2022 16:52:55 +1300 Subject: [PATCH] [Fix] Fix handling of short option with non-trivial equals Rework -a=bc handling Fixes #5. --- index.js | 4 ++-- test/kv_short.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 536fc5b..69fdd49 100644 --- a/index.js +++ b/index.js @@ -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; } diff --git a/test/kv_short.js b/test/kv_short.js index 1578f05..6d1b53a 100644 --- a/test/kv_short.js +++ b/test/kv_short.js @@ -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', _: [] }); +});