Skip to content

Commit e606f74

Browse files
VOvchinnikovsagikazarmark
authored andcommitted
fix: made InConfig process paths correctly
1 parent 2062cd6 commit e606f74

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

viper.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,11 +1404,13 @@ func (v *Viper) realKey(key string) string {
14041404
func InConfig(key string) bool { return v.InConfig(key) }
14051405

14061406
func (v *Viper) InConfig(key string) bool {
1407+
lcaseKey := strings.ToLower(key)
1408+
14071409
// if the requested key is an alias, then return the proper key
1408-
key = v.realKey(key)
1410+
lcaseKey = v.realKey(lcaseKey)
1411+
path := strings.Split(lcaseKey, v.keyDelim)
14091412

1410-
_, exists := v.config[key]
1411-
return exists
1413+
return v.searchIndexableWithPathPrefixes(v.config, path) != nil
14121414
}
14131415

14141416
// SetDefault sets the default value for this key.

viper_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ func TestUnmarshaling(t *testing.T) {
382382

383383
unmarshalReader(r, v.config)
384384
assert.True(t, InConfig("name"))
385+
assert.True(t, InConfig("clothing.jacket"))
385386
assert.False(t, InConfig("state"))
387+
assert.False(t, InConfig("clothing.hat"))
386388
assert.Equal(t, "steve", Get("name"))
387389
assert.Equal(t, []interface{}{"skateboarding", "snowboarding", "go"}, Get("hobbies"))
388390
assert.Equal(t, map[string]interface{}{"jacket": "leather", "trousers": "denim", "pants": map[string]interface{}{"size": "large"}}, Get("clothing"))
@@ -1239,7 +1241,9 @@ func TestReadBufConfig(t *testing.T) {
12391241
t.Log(v.AllKeys())
12401242

12411243
assert.True(t, v.InConfig("name"))
1244+
assert.True(t, v.InConfig("clothing.jacket"))
12421245
assert.False(t, v.InConfig("state"))
1246+
assert.False(t, v.InConfig("clothing.hat"))
12431247
assert.Equal(t, "steve", v.Get("name"))
12441248
assert.Equal(t, []interface{}{"skateboarding", "snowboarding", "go"}, v.Get("hobbies"))
12451249
assert.Equal(t, map[string]interface{}{"jacket": "leather", "trousers": "denim", "pants": map[string]interface{}{"size": "large"}}, v.Get("clothing"))

0 commit comments

Comments
 (0)