Skip to content

Commit

Permalink
fix: parse options ending with 3+ hyphens (#434)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
0x2b3bfa0 and bcoe authored Jul 5, 2022
1 parent a030551 commit 4f1060b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/yargs-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class YargsParser {
if (arg !== '--' && isUnknownOptionAsArg(arg)) {
pushPositional(arg)
// ---, ---=, ----, etc,
} else if (truncatedArg.match(/---+(=|$)/)) {
} else if (truncatedArg.match(/^---+(=|$)/)) {
// options without key name are invalid.
pushPositional(arg)
continue
Expand Down
7 changes: 7 additions & 0 deletions test/yargs-parser.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3588,6 +3588,13 @@ describe('yargs-parser', function () {
args.bar.should.equal('--goodnight moon')
})

// see: https://github.com/yargs/yargs-parser/issues/433
it('handles strings with three or more trailing dashes', function () {
const args = parser('--foo "hello---" --bar="world---"')
args.foo.should.equal('hello---')
args.bar.should.equal('world---')
})

it('respects inner quotes (string)', function () {
const args = parser('cmd --foo ""Hello"" --bar ""World"" --baz="":)""')
args.foo.should.equal('"Hello"')
Expand Down

0 comments on commit 4f1060b

Please sign in to comment.