Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9ec4d27

Browse filesBrowse files
shadowspawnljharb
authored andcommitted
[Fix] Fix long option followed by single dash
Fixes #15
1 parent ba92fe6 commit 9ec4d27
Copy full SHA for 9ec4d27

File tree

2 files changed

+12
-2
lines changed
Filter options

2 files changed

+12
-2
lines changed

‎index.js

Copy file name to clipboardExpand all lines: index.js
+1-1Lines changed: 1 addition & 1 deletion
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

Copy file name to clipboardExpand all lines: test/dash.js
+11-1Lines changed: 11 additions & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.