Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1464,10 +1464,12 @@ func Set(key string, value any) { v.Set(key, value) }

func (v *Viper) Set(key string, value any) {
// If alias passed in, then set the proper override

key = v.realKey(strings.ToLower(key))
value = toCaseInsensitiveValue(value)

path := strings.Split(key, v.keyDelim)
path := strings.Split(key, strings.ToLower(v.keyDelim))
Comment thread
maxBRT marked this conversation as resolved.
Outdated

lastKey := strings.ToLower(path[len(path)-1])
deepestMap := deepSearch(v.override, path[0:len(path)-1])

Expand Down
11 changes: 11 additions & 0 deletions viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2718,3 +2718,14 @@ func skipWindows(t *testing.T) {
t.Skip("Skip test on Windows")
}
}

// Test the Set method with key delimiter for case insenitivty
func TestUpperCaseKeyDelimiter(t *testing.T) {
Comment thread
maxBRT marked this conversation as resolved.
Outdated
v := NewWithOptions(KeyDelimiter("Z"))
v.Set("fooZbar", "Foo Bar Baz")

got := v.Get("foo")
want := map[string]any{"bar": "Foo Bar Baz"}

assert.Equal(t, want, got)
}