Skip to content

Commit

Permalink
fix: inner objects in configs had their keys appended to top-level ke…
Browse files Browse the repository at this point in the history
…y when dot-notation was disabled (#72)
  • Loading branch information
bcoe authored Dec 1, 2016
1 parent 0f0fb2d commit 0b1b5f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ function parse (args, opts) {
var value = config[key]
var fullKey = prev ? prev + '.' + key : key

if (Object.prototype.toString.call(value) === '[object Object]') {
// if the value is an inner object and we have dot-notation
// enabled, treat inner objects in config the same as
// heavily nested dot notations (foo.bar.apple).
if (typeof value === 'object' && !Array.isArray(value) && configuration['dot-notation']) {
// if the value is an object but not an array, check nested object
setConfigObject(value, fullKey)
} else {
Expand Down
25 changes: 25 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,31 @@ describe('yargs-parser', function () {
expect(parsed['foo.bar']).to.equal('banana')
expect(parsed).not.to.include.keys('f.bar')
})

// addresses https://github.com/yargs/yargs/issues/716
it('does not append nested-object keys from config to top-level key', function () {
var parsed = parser([], {
alias: {
'foo': ['f']
},
configuration: {
'dot-notation': false
},
configObjects: [
{
'website.com': {
a: 'b',
b: 'c'
}
}
]
})

parsed['website.com'].should.deep.equal({
a: 'b',
b: 'c'
})
})
})

describe('parse numbers', function () {
Expand Down

0 comments on commit 0b1b5f9

Please sign in to comment.