Skip to content

Commit 4f1060b

Browse files
0x2b3bfa0bcoe
andauthored
fix: parse options ending with 3+ hyphens (#434)
Before this commit, options ending with three or more hyphens were being parsed as positional arguments, because a regular expression didn't have a start anchor. Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent a030551 commit 4f1060b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/yargs-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export class YargsParser {
225225
if (arg !== '--' && isUnknownOptionAsArg(arg)) {
226226
pushPositional(arg)
227227
// ---, ---=, ----, etc,
228-
} else if (truncatedArg.match(/---+(=|$)/)) {
228+
} else if (truncatedArg.match(/^---+(=|$)/)) {
229229
// options without key name are invalid.
230230
pushPositional(arg)
231231
continue

test/yargs-parser.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,6 +3588,13 @@ describe('yargs-parser', function () {
35883588
args.bar.should.equal('--goodnight moon')
35893589
})
35903590

3591+
// see: https://github.com/yargs/yargs-parser/issues/433
3592+
it('handles strings with three or more trailing dashes', function () {
3593+
const args = parser('--foo "hello---" --bar="world---"')
3594+
args.foo.should.equal('hello---')
3595+
args.bar.should.equal('world---')
3596+
})
3597+
35913598
it('respects inner quotes (string)', function () {
35923599
const args = parser('cmd --foo ""Hello"" --bar ""World"" --baz="":)""')
35933600
args.foo.should.equal('"Hello"')

0 commit comments

Comments
 (0)