Skip to content
Open
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
24 changes: 24 additions & 0 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,9 @@ func (v *Viper) getSettings(keys []string) map[string]any {
m := map[string]any{}
// start from the list of keys, and construct the map one value at a time
for _, k := range keys {
if v.isPathShadowedByOverride(strings.Split(k, v.keyDelim)) {
continue
}
value := v.Get(k)
if value == nil {
// should not happen, since AllKeys() returns only keys holding a value,
Expand All @@ -2073,6 +2076,27 @@ func (v *Viper) getSettings(keys []string) map[string]any {
return m
}

func (v *Viper) isPathShadowedByOverride(path []string) bool {
if len(path) < 2 {
return false
}

for i := 1; i < len(path); i++ {
parentPath := path[0:i]
if v.searchMap(v.override, parentPath) == nil {
continue
}

if v.searchMap(v.override, path) != nil {
return false
}

return true
}

return false
}

// SetFs sets the filesystem to use to read configuration.
func SetFs(fs afero.Fs) { v.SetFs(fs) }

Expand Down