Skip to content

Commit cdb5e59

Browse files
carolynvssagikazarmark
authored andcommitted
Fix merging a key into a nil target
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 <[email protected]>
1 parent 36be6bf commit cdb5e59

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

viper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ func mergeMaps(
18261826

18271827
svType := reflect.TypeOf(sv)
18281828
tvType := reflect.TypeOf(tv)
1829-
if svType != tvType {
1829+
if tvType != nil && svType != tvType { // Allow for the target to be nil
18301830
jww.ERROR.Printf(
18311831
"svType != tvType; key=%s, st=%v, tt=%v, sv=%v, tv=%v",
18321832
sk, svType, tvType, sv, tv)

viper_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,7 @@ hello:
16951695
pop: 37890
16961696
largenum: 765432101234567
16971697
num2pow63: 9223372036854775808
1698+
universe: null
16981699
world:
16991700
- us
17001701
- uk

0 commit comments

Comments
 (0)