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:
+1
-1
@@ -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) {
|
func scanBasicString(b []byte) ([]byte, []byte, error) {
|
||||||
|
|||||||
@@ -1740,6 +1740,12 @@ func TestIssue586(t *testing.T) {
|
|||||||
require.Error(t, err)
|
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
|
//nolint:funlen
|
||||||
func TestUnmarshalDecodeErrors(t *testing.T) {
|
func TestUnmarshalDecodeErrors(t *testing.T) {
|
||||||
examples := []struct {
|
examples := []struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user