mirror of
https://github.com/spf13/viper
synced 2024-12-23 12:07:02 +00:00
Fix InConfig to be case insensitive on the provided key
This commit is contained in:
parent
5ed0fc31f7
commit
0939e4373c
2 changed files with 3 additions and 2 deletions
4
viper.go
4
viper.go
|
@ -1033,9 +1033,9 @@ func (v *Viper) realKey(key string) string {
|
||||||
func InConfig(key string) bool { return v.InConfig(key) }
|
func InConfig(key string) bool { return v.InConfig(key) }
|
||||||
func (v *Viper) InConfig(key string) bool {
|
func (v *Viper) InConfig(key string) bool {
|
||||||
// if the requested key is an alias, then return the proper key
|
// if the requested key is an alias, then return the proper key
|
||||||
key = v.realKey(key)
|
key = v.realKey(strings.ToLower(key))
|
||||||
|
|
||||||
_, exists := v.config[key]
|
_, exists := v.config[strings.ToLower(key)]
|
||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -268,6 +268,7 @@ func TestUnmarshalling(t *testing.T) {
|
||||||
|
|
||||||
unmarshalReader(r, v.config)
|
unmarshalReader(r, v.config)
|
||||||
assert.True(t, InConfig("name"))
|
assert.True(t, InConfig("name"))
|
||||||
|
assert.True(t, InConfig("NAME"))
|
||||||
assert.False(t, InConfig("state"))
|
assert.False(t, InConfig("state"))
|
||||||
assert.Equal(t, "steve", Get("name"))
|
assert.Equal(t, "steve", Get("name"))
|
||||||
assert.Equal(t, []interface{}{"skateboarding", "snowboarding", "go"}, Get("hobbies"))
|
assert.Equal(t, []interface{}{"skateboarding", "snowboarding", "go"}, Get("hobbies"))
|
||||||
|
|
Loading…
Reference in a new issue