File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -452,7 +452,10 @@ function parse (args, opts) {
452452 var value = config [ key ]
453453 var fullKey = prev ? prev + '.' + key : key
454454
455- if ( Object . prototype . toString . call ( value ) === '[object Object]' ) {
455+ // if the value is an inner object and we have dot-notation
456+ // enabled, treat inner objects in config the same as
457+ // heavily nested dot notations (foo.bar.apple).
458+ if ( typeof value === 'object' && ! Array . isArray ( value ) && configuration [ 'dot-notation' ] ) {
456459 // if the value is an object but not an array, check nested object
457460 setConfigObject ( value , fullKey )
458461 } else {
Original file line number Diff line number Diff line change @@ -1886,6 +1886,31 @@ describe('yargs-parser', function () {
18861886 expect ( parsed [ 'foo.bar' ] ) . to . equal ( 'banana' )
18871887 expect ( parsed ) . not . to . include . keys ( 'f.bar' )
18881888 } )
1889+
1890+ // addresses https://github.com/yargs/yargs/issues/716
1891+ it ( 'does not append nested-object keys from config to top-level key' , function ( ) {
1892+ var parsed = parser ( [ ] , {
1893+ alias : {
1894+ 'foo' : [ 'f' ]
1895+ } ,
1896+ configuration : {
1897+ 'dot-notation' : false
1898+ } ,
1899+ configObjects : [
1900+ {
1901+ 'website.com' : {
1902+ a : 'b' ,
1903+ b : 'c'
1904+ }
1905+ }
1906+ ]
1907+ } )
1908+
1909+ parsed [ 'website.com' ] . should . deep . equal ( {
1910+ a : 'b' ,
1911+ b : 'c'
1912+ } )
1913+ } )
18891914 } )
18901915
18911916 describe ( 'parse numbers' , function ( ) {
You can’t perform that action at this time.
0 commit comments