Skip to content

Commit

Permalink
Fix merging a key into a nil target
Browse files Browse the repository at this point in the history
When merging a key where the target value is nil, the type of the target
and source do not match. What currently happens is an error is logged
and the key is skipped.

I have changed it so that it does the same thing as when the target key
is missing: copy the source value to the target.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
  • Loading branch information
carolynvs authored and sagikazarmark committed May 17, 2021
1 parent 36be6bf commit cdb5e59
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ func mergeMaps(

svType := reflect.TypeOf(sv)
tvType := reflect.TypeOf(tv)
if svType != tvType {
if tvType != nil && svType != tvType { // Allow for the target to be nil
jww.ERROR.Printf(
"svType != tvType; key=%s, st=%v, tt=%v, sv=%v, tv=%v",
sk, svType, tvType, sv, tv)
Expand Down
1 change: 1 addition & 0 deletions viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,7 @@ hello:
pop: 37890
largenum: 765432101234567
num2pow63: 9223372036854775808
universe: null
world:
- us
- uk
Expand Down

0 comments on commit cdb5e59

Please sign in to comment.