Skip to content

Commit 585ae8f

Browse files
authored
fix(populate--): -- should always be array (#354)
1 parent a4000b6 commit 585ae8f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/yargs-parser.ts

+5
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ export class YargsParser {
214214
// any unknown option (except for end-of-options, "--")
215215
if (arg !== '--' && isUnknownOptionAsArg(arg)) {
216216
pushPositional(arg)
217+
// ---, ---=, ----, etc,
218+
} else if (arg.match(/---+(=|$)/)) {
219+
// options without key name are invalid.
220+
pushPositional(arg)
221+
continue
217222
// -- separated by =
218223
} else if (arg.match(/^--.+=/) || (
219224
!configuration['short-option-groups'] && arg.match(/^-.+=/)

test/yargs-parser.cjs

+11
Original file line numberDiff line numberDiff line change
@@ -3244,6 +3244,17 @@ describe('yargs-parser', function () {
32443244
k: true
32453245
})
32463246
})
3247+
// See: https://github.com/yargs/yargs/issues/1869
3248+
// ----=hello ---=hello ---- hello.
3249+
it('should not populate "--" for key values other than "--"', () => {
3250+
const argv = parser('----=test', {
3251+
configuration: {
3252+
'populate--': true
3253+
}
3254+
})
3255+
argv._.should.eql(['----=test'])
3256+
expect(argv['--']).to.equal(undefined)
3257+
})
32473258
// see: https://github.com/yargs/yargs/issues/1489
32483259
it('should identify "hasOwnProperty" as unknown option', () => {
32493260
const argv = parser('--known-arg=1 --hasOwnProperty=33', {

0 commit comments

Comments
 (0)