From cdb5e5976f9bb9e9ede7da170187742fc4bd7e9f Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Wed, 12 May 2021 17:09:19 -0500 Subject: [PATCH] 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 --- viper.go | 2 +- viper_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/viper.go b/viper.go index 50b478029..a89efe978 100644 --- a/viper.go +++ b/viper.go @@ -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) diff --git a/viper_test.go b/viper_test.go index 45bf8e9ba..a5bbbd468 100644 --- a/viper_test.go +++ b/viper_test.go @@ -1695,6 +1695,7 @@ hello: pop: 37890 largenum: 765432101234567 num2pow63: 9223372036854775808 + universe: null world: - us - uk