From 54541f4c038b78bc45aa65d264a958ee61b3607a Mon Sep 17 00:00:00 2001 From: Sonny Alves Dias Date: Sat, 16 Dec 2023 12:05:51 +0800 Subject: [PATCH] Sort keys before looping through them to avoid overwriting Signed-off-by: Sonny Alves Dias --- viper.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/viper.go b/viper.go index 122280b11..575f2f2d5 100644 --- a/viper.go +++ b/viper.go @@ -28,6 +28,7 @@ import ( "os" "path/filepath" "reflect" + "sort" "strconv" "strings" "sync" @@ -2138,6 +2139,7 @@ func (v *Viper) AllSettings() map[string]any { func (v *Viper) getSettings(keys []string) map[string]any { m := map[string]any{} + sort.Strings(keys) // start from the list of keys, and construct the map one value at a time for _, k := range keys { value := v.Get(k)