Skip to content

Commit

Permalink
fix(populate--): -- should always be array (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Feb 22, 2021
1 parent a4000b6 commit 585ae8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/yargs-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/^-.+=/)
Expand Down
11 changes: 11 additions & 0 deletions test/yargs-parser.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down

0 comments on commit 585ae8f

Please sign in to comment.