Revert the effective changes of #673

This commit is contained in:
Mark Sagi-Kazar 2019-09-27 17:18:11 +02:00 committed by Márk Sági-Kazár
parent 398adc5a7d
commit 71509d2887
2 changed files with 2 additions and 36 deletions

View File

@ -1789,24 +1789,6 @@ outer:
return shadow return shadow
} }
// Converts a fully qualified map key into a list of relative
// map keys, allowing for keys to contain the delimiter themselves
func keyComponents(v *Viper, key string) []string {
var result []string
components := strings.Split(key, v.keyDelim)
for index := 0; index < len(components); index++ {
potentialKey := strings.Join(components[0:index], v.keyDelim)
if v.Get(potentialKey) != nil {
result = append(result, potentialKey)
}
}
result = append(result, key)
for i := len(result) - 1; i > 0; i-- {
result[i] = strings.Replace(result[i], result[i-1]+v.keyDelim, "", 1)
}
return result
}
// AllSettings merges all settings and returns them as a map[string]interface{}. // AllSettings merges all settings and returns them as a map[string]interface{}.
func AllSettings() map[string]interface{} { return v.AllSettings() } func AllSettings() map[string]interface{} { return v.AllSettings() }
func (v *Viper) AllSettings() map[string]interface{} { func (v *Viper) AllSettings() map[string]interface{} {
@ -1819,7 +1801,7 @@ func (v *Viper) AllSettings() map[string]interface{} {
// check just in case anything changes // check just in case anything changes
continue continue
} }
path := keyComponents(v, k) path := strings.Split(k, v.keyDelim)
lastKey := strings.ToLower(path[len(path)-1]) lastKey := strings.ToLower(path[len(path)-1])
deepestMap := deepSearch(m, path[0:len(path)-1]) deepestMap := deepSearch(m, path[0:len(path)-1])
// set innermost value // set innermost value

View File

@ -46,10 +46,6 @@ clothing:
age: 35 age: 35
eyes : brown eyes : brown
beard: true beard: true
emails:
steve@hacker.com:
created: 01/02/03
active: true
`) `)
var yamlExampleWithExtras = []byte(`Existing: true var yamlExampleWithExtras = []byte(`Existing: true
@ -535,8 +531,6 @@ func TestAllKeys(t *testing.T) {
"title_dotenv", "title_dotenv",
"type_dotenv", "type_dotenv",
"name_dotenv", "name_dotenv",
"emails.steve@hacker.com.active",
"emails.steve@hacker.com.created",
} }
dob, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z") dob, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z")
all := map[string]interface{}{ all := map[string]interface{}{
@ -547,13 +541,7 @@ func TestAllKeys(t *testing.T) {
}, },
"title": "TOML Example", "title": "TOML Example",
"ppu": 0.55, "ppu": 0.55,
"emails": map[string]interface{}{ "eyes": "brown",
"steve@hacker.com": map[string]interface{}{
"active": true,
"created": "01/02/03",
},
},
"eyes": "brown",
"clothing": map[string]interface{}{ "clothing": map[string]interface{}{
"trousers": "denim", "trousers": "denim",
"jacket": "leather", "jacket": "leather",
@ -1316,10 +1304,6 @@ clothing:
pants: pants:
size: large size: large
trousers: denim trousers: denim
emails:
steve@hacker.com:
active: true
created: 01/02/03
eyes: brown eyes: brown
hacker: true hacker: true
hobbies: hobbies: