File tree 2 files changed +29
-1
lines changed
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) {
452
452
var value = config [ key ]
453
453
var fullKey = prev ? prev + '.' + key : key
454
454
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' ] ) {
456
459
// if the value is an object but not an array, check nested object
457
460
setConfigObject ( value , fullKey )
458
461
} else {
Original file line number Diff line number Diff line change @@ -1886,6 +1886,31 @@ describe('yargs-parser', function () {
1886
1886
expect ( parsed [ 'foo.bar' ] ) . to . equal ( 'banana' )
1887
1887
expect ( parsed ) . not . to . include . keys ( 'f.bar' )
1888
1888
} )
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
+ } )
1889
1914
} )
1890
1915
1891
1916
describe ( 'parse numbers' , function ( ) {
You can’t perform that action at this time.
0 commit comments