Fix key/value parsing returning erroneous duplicate entry errors
This commit is contained in:
parent
3b1620b5ef
commit
8b4f77b223
@ -66,7 +66,7 @@ func Parse (reader io.Reader) (File, error) {
|
||||
var specifiedValues map[string] struct { }
|
||||
for {
|
||||
line, err := buffer.ReadString('\n')
|
||||
if errors.Is(err, io.EOF) { return file, nil }
|
||||
if errors.Is(err, io.EOF) { break }
|
||||
if err != nil { return nil, err }
|
||||
|
||||
line = strings.TrimSpace(line)
|
||||
@ -109,15 +109,20 @@ func Parse (reader io.Reader) (File, error) {
|
||||
group[key] = entry
|
||||
} else {
|
||||
// default value
|
||||
_, exists := group[key]
|
||||
if exists { return nil, ErrDuplicateEntry }
|
||||
entry := newEntry()
|
||||
_, specified := specifiedValues[key]
|
||||
if specified { return nil, ErrDuplicateEntry }
|
||||
|
||||
entry, exists := group[key]
|
||||
if !exists { entry = newEntry() }
|
||||
|
||||
entry.Value = value
|
||||
group[key] = entry
|
||||
specifiedValues[key] = struct { } { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func newEntry () Entry {
|
||||
|
@ -168,3 +168,57 @@ File {
|
||||
"Icon": testEntry("fooview-new"),
|
||||
},
|
||||
})}
|
||||
|
||||
func TestParseLocalized (test *testing.T) {
|
||||
testParseString(test, `
|
||||
[Group 0]
|
||||
Name=something
|
||||
Name[xx_XX]=other thing
|
||||
Name[yy_YY]=another thing
|
||||
Name[zz_ZZ]=yet another thing
|
||||
[Group 1]
|
||||
Name[xx_XX]=other thing
|
||||
Name[yy_YY]=another thing
|
||||
Name=something
|
||||
Name[zz_ZZ]=yet another thing
|
||||
`,
|
||||
File {
|
||||
"Group 0": Group {
|
||||
"Name": Entry {
|
||||
Value: "something",
|
||||
Localized: map[locale.Locale] string {
|
||||
locale.Locale {
|
||||
Lang: "xx",
|
||||
Country: "XX",
|
||||
}: "other thing",
|
||||
locale.Locale {
|
||||
Lang: "yy",
|
||||
Country: "YY",
|
||||
}: "another thing",
|
||||
locale.Locale {
|
||||
Lang: "zz",
|
||||
Country: "ZZ",
|
||||
}: "yet another thing",
|
||||
},
|
||||
},
|
||||
},
|
||||
"Group 1": Group {
|
||||
"Name": Entry {
|
||||
Value: "something",
|
||||
Localized: map[locale.Locale] string {
|
||||
locale.Locale {
|
||||
Lang: "xx",
|
||||
Country: "XX",
|
||||
}: "other thing",
|
||||
locale.Locale {
|
||||
Lang: "yy",
|
||||
Country: "YY",
|
||||
}: "another thing",
|
||||
locale.Locale {
|
||||
Lang: "zz",
|
||||
Country: "ZZ",
|
||||
}: "yet another thing",
|
||||
},
|
||||
},
|
||||
},
|
||||
})}
|
||||
|
Loading…
Reference in New Issue
Block a user