diff --git a/viper.go b/viper.go index 7a49a0a..d701632 100644 --- a/viper.go +++ b/viper.go @@ -788,8 +788,10 @@ func (v *Viper) find(key string) interface{} { if source != nil { if reflect.TypeOf(source).Kind() == reflect.Map { val := v.searchMap(cast.ToStringMap(source), path[1:]) - jww.TRACE.Println(key, "found in nested config:", val) - return val + if val != nil { + jww.TRACE.Println(key, "found in nested config:", val) + return val + } } } } diff --git a/viper_test.go b/viper_test.go index 858caff..8a6d535 100644 --- a/viper_test.go +++ b/viper_test.go @@ -883,3 +883,12 @@ func TestUnmarshalingWithAliases(t *testing.T) { assert.Equal(t, &C, &config{Id: 1, FirstName: "Steve", Surname: "Owen"}) } + +func TestShadowedNestedValue(t *testing.T) { + polyester := "polyester" + initYAML() + SetDefault("clothing.shirt", polyester) + + assert.Equal(t, GetString("clothing.jacket"), "leather") + assert.Equal(t, GetString("clothing.shirt"), polyester) +}