scanner: fix error reporting for last comments (#591)

When an invalid TOML expression ends with a comment before the end of
file, the decode error would take a nil from scanComment, which is not
part of the document.

Fixes #588
This commit is contained in:
Thomas Pelletier
2021-09-08 21:54:30 -04:00
committed by GitHub
parent a0d685d482
commit f34c9c332f
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ func scanComment(b []byte) ([]byte, []byte) {
}
}
return b, nil
return b, b[len(b):]
}
func scanBasicString(b []byte) ([]byte, []byte, error) {
+6
View File
@@ -1740,6 +1740,12 @@ func TestIssue586(t *testing.T) {
require.Error(t, err)
}
func TestIssue588(t *testing.T) {
var v interface{}
err := toml.Unmarshal([]byte(`a=[1#`), &v)
require.Error(t, err)
}
//nolint:funlen
func TestUnmarshalDecodeErrors(t *testing.T) {
examples := []struct {