Don't crash when assigning group array to array

This commit is contained in:
Thomas Pelletier
2015-12-01 13:56:31 +01:00
parent ab7a652912
commit a6c6ad1f5f
2 changed files with 8 additions and 1 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ func (p *tomlParser) parseGroupArray() tomlParserStateFn {
var array []*TomlTree
if destTree == nil {
array = make([]*TomlTree, 0)
} else if destTree.([]*TomlTree) != nil {
} else if target, ok := destTree.([]*TomlTree); ok && target != nil {
array = destTree.([]*TomlTree)
} else {
p.raiseError(key, "key %s is already assigned and not of type group array", key)
+7
View File
@@ -626,3 +626,10 @@ func TestDoubleEqual(t *testing.T) {
t.Error("Bad error message:", err.Error())
}
}
func TestGroupArrayReassign(t *testing.T) {
_, err := Load("[hello]\n[[hello]]")
if err.Error() != "(2, 3): key \"hello\" is already assigned and not of type group array" {
t.Error("Bad error message:", err.Error())
}
}