From a5d4cd727bdbb4e86e4a3397e36381ea5b363a3e Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 27 Apr 2024 20:16:46 -0400 Subject: [PATCH] Minor key/value parsing fixes --- key-value/key-value.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/key-value/key-value.go b/key-value/key-value.go index e109a8f..30ee79e 100644 --- a/key-value/key-value.go +++ b/key-value/key-value.go @@ -14,6 +14,7 @@ package keyValue import "io" import "fmt" import "bufio" +import "errors" import "strings" import "strconv" import "unicode" @@ -65,7 +66,9 @@ func Parse (reader io.Reader) (File, error) { var specifiedValues map[string] struct { } for { line, err := buffer.ReadString('\n') - if err != nil { return nil, err } + if errors.Is(err, io.EOF) { return file, nil } + if err != nil { return nil, err } + line = strings.TrimSpace(line) switch { @@ -167,8 +170,10 @@ func parseEntry (line string) (key, val string, loc locale.Locale, err error) { } if state != getVal { err = ErrInvalidEntry; return } - loc, err = locale.Parse(locb.String()) - if err != nil { return} + if locb.Len() > 0 { + loc, err = locale.Parse(locb.String()) + if err != nil { return} + } key = strings.TrimSpace(keyb.String()) val = strings.TrimSpace(valb.String())