Skip to content

Commit 9ec4d27

Browse files
shadowspawnljharb
authored andcommittedJan 6, 2023
[Fix] Fix long option followed by single dash
Fixes #15
1 parent ba92fe6 commit 9ec4d27

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ module.exports = function (args, opts) {
164164
next = args[i + 1];
165165
if (
166166
next !== undefined
167-
&& !(/^-/).test(next)
167+
&& !(/^(-|--)[^-]/).test(next)
168168
&& !flags.bools[key]
169169
&& !flags.allBools
170170
&& (aliases[key] ? !aliasIsBoolean(key) : true)

‎test/dash.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ var parse = require('../');
44
var test = require('tape');
55

66
test('-', function (t) {
7-
t.plan(5);
7+
t.plan(6);
88
t.deepEqual(parse(['-n', '-']), { n: '-', _: [] });
9+
t.deepEqual(parse(['--nnn', '-']), { nnn: '-', _: [] });
910
t.deepEqual(parse(['-']), { _: ['-'] });
1011
t.deepEqual(parse(['-f-']), { f: '-', _: [] });
1112
t.deepEqual(
@@ -31,3 +32,12 @@ test('move arguments after the -- into their own `--` array', function (t) {
3132
{ name: 'John', _: ['before'], '--': ['after'] }
3233
);
3334
});
35+
36+
test('--- option value', function (t) {
37+
// A multi-dash value is largely an edge case, but check the behaviour is as expected,
38+
// and in particular the same for short option and long option (as made consistent in Jan 2023).
39+
t.plan(2);
40+
t.deepEqual(parse(['-n', '---']), { n: '---', _: [] });
41+
t.deepEqual(parse(['--nnn', '---']), { nnn: '---', _: [] });
42+
});
43+

0 commit comments

Comments
 (0)
Please sign in to comment.