From 7da613aa94231335c13762ae93105b421c00e06f Mon Sep 17 00:00:00 2001 From: gopherclass Date: Mon, 9 Mar 2020 19:37:51 +0900 Subject: [PATCH] Fix panic while writing invalid ini --- viper.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/viper.go b/viper.go index 7b12b36..823339c 100644 --- a/viper.go +++ b/viper.go @@ -1616,6 +1616,10 @@ func (v *Viper) marshalWriter(f afero.File, configType string) error { for i := 0; i < len(keys); i++ { key := keys[i] lastSep := strings.LastIndex(key, ".") + if lastSep < 0 { + err := fmt.Errorf("missing key for %s", key) + return ConfigMarshalError{err} + } sectionName := key[:(lastSep)] keyName := key[(lastSep + 1):] if sectionName == "default" {