From 074ed18f7eff65bbd8756a61a1b662290cd13cd4 Mon Sep 17 00:00:00 2001 From: Carlos Henrique Guardao Gandarez Date: Tue, 26 May 2020 09:05:55 -0300 Subject: [PATCH] fix panic while saving ini file --- viper.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/viper.go b/viper.go index f61f4ed..25f2a04 100644 --- a/viper.go +++ b/viper.go @@ -1644,9 +1644,12 @@ func (v *Viper) marshalWriter(f afero.File, configType string) error { for i := 0; i < len(keys); i++ { key := keys[i] lastSep := strings.LastIndex(key, ".") - sectionName := key[:(lastSep)] + sectionName := "" + if lastSep > 0 { + sectionName = key[:(lastSep)] + } keyName := key[(lastSep + 1):] - if sectionName == "default" { + if sectionName == ini.DefaultSection { sectionName = "" } cfg.Section(sectionName).Key(keyName).SetValue(v.Get(key).(string))