From f34c9c332fa0e0b8d3b55c961b46828d92c2cd1c Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Wed, 8 Sep 2021 21:54:30 -0400 Subject: [PATCH] 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 --- scanner.go | 2 +- unmarshaler_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scanner.go b/scanner.go index b203702..043adc3 100644 --- a/scanner.go +++ b/scanner.go @@ -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) { diff --git a/unmarshaler_test.go b/unmarshaler_test.go index 43d49a3..30fc53d 100644 --- a/unmarshaler_test.go +++ b/unmarshaler_test.go @@ -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 {