diff --git a/viper.go b/viper.go index a2633b0..08019ef 100644 --- a/viper.go +++ b/viper.go @@ -526,7 +526,10 @@ func (v *Viper) Sub(key string) *Viper { subv := New() data := v.Get(key) if reflect.TypeOf(data).Kind() == reflect.Map { - subv.config = cast.ToStringMap(data) + m := cast.ToStringMap(data) + for k, v := range m { + subv.config[strings.ToLower(k)] = v + } return subv } else { return nil diff --git a/viper_test.go b/viper_test.go index 858caff..4b023f4 100644 --- a/viper_test.go +++ b/viper_test.go @@ -41,6 +41,15 @@ var yamlExampleWithExtras = []byte(`Existing: true Bogus: true `) +var yamlExampleWithSubtreeCaps = []byte(`Hacker: true +name: steve +clothing: + JACKET: leather + TROUSERS: denim + pants: + size: large +`) + type testUnmarshalExtra struct { Existing bool } @@ -760,6 +769,18 @@ func TestSub(t *testing.T) { assert.Equal(t, subv, (*Viper)(nil)) } +func TestSubWithCaps(t *testing.T) { + v := New() + v.SetConfigType("yaml") + v.ReadConfig(bytes.NewBuffer(yamlExampleWithSubtreeCaps)) + + subv := v.Sub("clothing") + assert.Equal(t, v.Get("clothing.JACKET"), subv.Get("jacket")) + + subv = v.Sub("clothing.pants.size") + assert.Equal(t, subv, (*Viper)(nil)) +} + var yamlMergeExampleTgt = []byte(` hello: pop: 37890