Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inner objects in configs had their keys appended to top-level key when dot-notation was disabled #72

Merged
merged 1 commit into from Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -440,7 +440,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
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