Fix panic while writing invalid ini

This commit is contained in:
gopherclass 2020-03-09 19:37:51 +09:00
parent 896fc959b3
commit 7da613aa94

View file

@ -1616,6 +1616,10 @@ func (v *Viper) marshalWriter(f afero.File, configType string) error {
for i := 0; i < len(keys); i++ { for i := 0; i < len(keys); i++ {
key := keys[i] key := keys[i]
lastSep := strings.LastIndex(key, ".") lastSep := strings.LastIndex(key, ".")
if lastSep < 0 {
err := fmt.Errorf("missing key for %s", key)
return ConfigMarshalError{err}
}
sectionName := key[:(lastSep)] sectionName := key[:(lastSep)]
keyName := key[(lastSep + 1):] keyName := key[(lastSep + 1):]
if sectionName == "default" { if sectionName == "default" {