Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse options ending with 3+ hyphens #434

Merged
merged 6 commits into from Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/yargs-parser.ts
Expand Up @@ -225,7 +225,7 @@ export class YargsParser {
if (arg !== '--' && isUnknownOptionAsArg(arg)) {
pushPositional(arg)
// ---, ---=, ----, etc,
} else if (truncatedArg.match(/---+(=|$)/)) {
} else if (truncatedArg.match(/^---+(=|$)/)) {
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
// options without key name are invalid.
pushPositional(arg)
continue
Expand Down
7 changes: 7 additions & 0 deletions test/yargs-parser.cjs
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