From 31d637a26ea58018ab06c2050bc5b30f3430f861 Mon Sep 17 00:00:00 2001 From: 0x2b3bfa0 <0x2b3bfa0+git@googlemail.com> Date: Sun, 6 Feb 2022 00:36:09 +0100 Subject: [PATCH 1/2] fix: parse options ending with 3+ hyphens 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. Closes #433 --- lib/yargs-parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/yargs-parser.ts b/lib/yargs-parser.ts index 571a0cbc..5f776705 100644 --- a/lib/yargs-parser.ts +++ b/lib/yargs-parser.ts @@ -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 From 94eeb8d76e210cdb445e6f856719c3d953ffca76 Mon Sep 17 00:00:00 2001 From: 0x2b3bfa0 <0x2b3bfa0+git@googlemail.com> Date: Sun, 27 Feb 2022 21:22:21 +0100 Subject: [PATCH 2/2] Add tests --- test/yargs-parser.cjs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/yargs-parser.cjs b/test/yargs-parser.cjs index aa6bf6bf..97add48c 100644 --- a/test/yargs-parser.cjs +++ b/test/yargs-parser.cjs @@ -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"')