Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (fn optionFunc) apply(v *Viper) {
// By default it's value is ".".
func KeyDelimiter(d string) Option {
return optionFunc(func(v *Viper) {
v.keyDelim = d
v.keyDelim = strings.ToLower(d)
})
}

Expand Down
12 changes: 12 additions & 0 deletions viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,18 @@ func TestKeyDelimiter(t *testing.T) {
assert.Equal(t, expected, actual)
}

func TestKeyDelimiterCase(t *testing.T) {
// A key delimiter containing uppercase letters must work the same as a
// lowercase one: keys are lowercased before lookup, so the delimiter must
// be lowercased as well for nested paths to resolve.
v := NewWithOptions(KeyDelimiter("A>B"))
v.SetConfigType("yaml")
require.NoError(t, v.unmarshalReader(strings.NewReader("severity:\n foo: warning\n"), v.config))

assert.Equal(t, "warning", v.Get("severityA>BFoo"))
assert.Equal(t, map[string]any{"severity": map[string]any{"foo": "warning"}}, v.AllSettings())
}

var yamlDeepNestedSlices = []byte(`TV:
- title: "The Expanse"
title_i18n:
Expand Down