From 585ae8ffad74cc02974f92d788e750137fd65146 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Sun, 21 Feb 2021 18:12:58 -0800 Subject: [PATCH] fix(populate--): -- should always be array (#354) --- lib/yargs-parser.ts | 5 +++++ test/yargs-parser.cjs | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/yargs-parser.ts b/lib/yargs-parser.ts index 02cc1272..b8bd8775 100644 --- a/lib/yargs-parser.ts +++ b/lib/yargs-parser.ts @@ -214,6 +214,11 @@ export class YargsParser { // any unknown option (except for end-of-options, "--") if (arg !== '--' && isUnknownOptionAsArg(arg)) { pushPositional(arg) + // ---, ---=, ----, etc, + } else if (arg.match(/---+(=|$)/)) { + // options without key name are invalid. + pushPositional(arg) + continue // -- separated by = } else if (arg.match(/^--.+=/) || ( !configuration['short-option-groups'] && arg.match(/^-.+=/) diff --git a/test/yargs-parser.cjs b/test/yargs-parser.cjs index 63504f19..f45256ed 100644 --- a/test/yargs-parser.cjs +++ b/test/yargs-parser.cjs @@ -3244,6 +3244,17 @@ describe('yargs-parser', function () { k: true }) }) + // See: https://github.com/yargs/yargs/issues/1869 + // ----=hello ---=hello ---- hello. + it('should not populate "--" for key values other than "--"', () => { + const argv = parser('----=test', { + configuration: { + 'populate--': true + } + }) + argv._.should.eql(['----=test']) + expect(argv['--']).to.equal(undefined) + }) // see: https://github.com/yargs/yargs/issues/1489 it('should identify "hasOwnProperty" as unknown option', () => { const argv = parser('--known-arg=1 --hasOwnProperty=33', {