unmarshal: fix non-terminated array error

Fixes #581
This commit is contained in:
Thomas Pelletier
2021-09-07 10:19:45 -04:00
committed by Thomas Pelletier
parent 40cfb6f458
commit 7e2fa1bc80
2 changed files with 8 additions and 1 deletions
+2 -1
View File
@@ -397,6 +397,7 @@ func (p *parser) parseValArray(b []byte) (ast.Reference, []byte, error) {
// array-values =/ ws-comment-newline val ws-comment-newline [ array-sep ]
// array-sep = %x2C ; , Comma
// ws-comment-newline = *( wschar / [ comment ] newline )
arrayStart := b
b = b[1:]
parent := p.builder.Push(ast.Node{
@@ -415,7 +416,7 @@ func (p *parser) parseValArray(b []byte) (ast.Reference, []byte, error) {
}
if len(b) == 0 {
return parent, nil, newDecodeError(b, "array is incomplete")
return parent, nil, newDecodeError(arrayStart[:1], "array is incomplete")
}
if b[0] == ']' {
+6
View File
@@ -1728,6 +1728,12 @@ func TestIssue579(t *testing.T) {
require.Error(t, err)
}
func TestIssue581(t *testing.T) {
var v interface{}
err := toml.Unmarshal([]byte(`P=[#`), &v)
require.Error(t, err)
}
//nolint:funlen
func TestUnmarshalDecodeErrors(t *testing.T) {
examples := []struct {