unmarshal: don't crash on unterminated inline table (#587)

Fixes #586
This commit is contained in:
Thomas Pelletier
2021-09-07 20:08:59 -04:00
committed by GitHub
parent 4a5ae9e81e
commit a0d685d482
2 changed files with 12 additions and 0 deletions
+6
View File
@@ -353,7 +353,13 @@ func (p *parser) parseInlineTable(b []byte) (ast.Reference, []byte, error) {
var err error
for len(b) > 0 {
previousB := b
b = p.parseWhitespace(b)
if len(b) == 0 {
return parent, nil, newDecodeError(previousB[:1], "inline table is incomplete")
}
if b[0] == '}' {
break
}
+6
View File
@@ -1734,6 +1734,12 @@ func TestIssue581(t *testing.T) {
require.Error(t, err)
}
func TestIssue586(t *testing.T) {
var v interface{}
err := toml.Unmarshal([]byte(`a={ `), &v)
require.Error(t, err)
}
//nolint:funlen
func TestUnmarshalDecodeErrors(t *testing.T) {
examples := []struct {