mirror of
https://github.com/spf13/viper
synced 2024-12-23 12:07:02 +00:00
Fix panic while writing invalid ini
This commit is contained in:
parent
896fc959b3
commit
7da613aa94
1 changed files with 4 additions and 0 deletions
4
viper.go
4
viper.go
|
@ -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" {
|
||||||
|
|
Loading…
Reference in a new issue