mirror of
https://github.com/spf13/viper
synced 2024-11-05 12:47:01 +00:00
Bugfix for Nested Key Casing
This patch fixes a bug with how Viper handle's key casing when keys are nested. While Viper is generally case-insensitive, this was not the case with regards to nested keys. This patch makes nested keys insensitive as well.
This commit is contained in:
parent
991d18afb2
commit
110492b300
1 changed files with 12 additions and 2 deletions
14
viper.go
14
viper.go
|
@ -404,7 +404,17 @@ func (v *Viper) searchMap(source map[string]interface{}, path []string) interfac
|
||||||
return source
|
return source
|
||||||
}
|
}
|
||||||
|
|
||||||
if next, ok := source[path[0]]; ok {
|
var ok bool
|
||||||
|
var next interface{}
|
||||||
|
for k, v := range source {
|
||||||
|
if strings.ToLower(k) == strings.ToLower(path[0]) {
|
||||||
|
ok = true
|
||||||
|
next = v
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
switch next.(type) {
|
switch next.(type) {
|
||||||
case map[interface{}]interface{}:
|
case map[interface{}]interface{}:
|
||||||
return v.searchMap(cast.ToStringMap(next), path[1:])
|
return v.searchMap(cast.ToStringMap(next), path[1:])
|
||||||
|
@ -454,7 +464,7 @@ func (v *Viper) Get(key string) interface{} {
|
||||||
val := v.find(lcaseKey)
|
val := v.find(lcaseKey)
|
||||||
|
|
||||||
if val == nil {
|
if val == nil {
|
||||||
source := v.find(path[0])
|
source := v.find(strings.ToLower(path[0]))
|
||||||
if source != nil {
|
if source != nil {
|
||||||
if reflect.TypeOf(source).Kind() == reflect.Map {
|
if reflect.TypeOf(source).Kind() == reflect.Map {
|
||||||
val = v.searchMap(cast.ToStringMap(source), path[1:])
|
val = v.searchMap(cast.ToStringMap(source), path[1:])
|
||||||
|
|
Loading…
Reference in a new issue