mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Prevent shadowning of keys when a nested key's value is nil.
This commit is contained in:
parent
c975dc1b4e
commit
03d0bb47ee
2 changed files with 13 additions and 2 deletions
6
viper.go
6
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue