This commit is contained in:
Justin Tulloss 2023-02-10 06:50:24 +09:00 committed by GitHub
commit 2662dc5e43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -948,7 +948,10 @@ func (v *Viper) Sub(key string) *Viper {
}
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
}
return nil

View file

@ -53,6 +53,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
}
@ -1908,6 +1917,18 @@ func TestWriteHiddenFile(t *testing.T) {
require.NoError(t, err)
}
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