From 63b8fee87b8e7a003216d5d77ba5d6decf3cfb0d Mon Sep 17 00:00:00 2001 From: John Gee Date: Fri, 6 Jan 2023 13:57:07 +1300 Subject: [PATCH] [Fix] Fix long option followed by single dash (#17) Fixes #15 --- index.js | 2 +- test/dash.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 63fce17..e6dba60 100644 --- a/index.js +++ b/index.js @@ -136,7 +136,7 @@ module.exports = function (args, opts) { next = args[i + 1]; if ( next !== undefined - && !(/^-/).test(next) + && !(/^(-|--)[^-]/).test(next) && !flags.bools[key] && !flags.allBools && (aliases[key] ? !flags.bools[aliases[key]] : true) diff --git a/test/dash.js b/test/dash.js index 66d9bbd..7078817 100644 --- a/test/dash.js +++ b/test/dash.js @@ -4,8 +4,9 @@ var parse = require('../'); var test = require('tape'); test('-', function (t) { - t.plan(5); + t.plan(6); t.deepEqual(parse(['-n', '-']), { n: '-', _: [] }); + t.deepEqual(parse(['--nnn', '-']), { nnn: '-', _: [] }); t.deepEqual(parse(['-']), { _: ['-'] }); t.deepEqual(parse(['-f-']), { f: '-', _: [] }); t.deepEqual( @@ -31,3 +32,12 @@ test('move arguments after the -- into their own `--` array', function (t) { { name: 'John', _: ['before'], '--': ['after'] } ); }); + +test('--- option value', function (t) { + // A multi-dash value is largely an edge case, but check the behaviour is as expected, + // and in particular the same for short option and long option (as made consistent in Jan 2023). + t.plan(2); + t.deepEqual(parse(['-n', '---']), { n: '---', _: [] }); + t.deepEqual(parse(['--nnn', '---']), { nnn: '---', _: [] }); +}); +