From e389d8d2e855d605af029e9b07935204074338bb Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Mar 2026 01:24:43 +0000 Subject: [PATCH] Fix parser error pointing to wrong line when last line has no trailing newline When parsing a key without '=' at EOF (e.g., "a = 1\nb = 2\nc"), the error highlight was an empty slice, causing subsliceOffset to return 0 and the error to point at line 1 instead of line 3. Pass the consumed key bytes as the highlight instead of the empty remainder. Fixes #1032 https://claude.ai/code/session_01UWv8pyc8P1ktAPfHpveixj --- errors_test.go | 6 ++++++ unstable/parser.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/errors_test.go b/errors_test.go index 73b7bdc1..3703bd0e 100644 --- a/errors_test.go +++ b/errors_test.go @@ -259,6 +259,12 @@ func TestDecodeError_Position(t *testing.T) { expectedRow: 3, minCol: 5, }, + { + name: "missing equals on last line without trailing newline", + doc: "a = 1\nb = 2\nc", + expectedRow: 3, + minCol: 1, + }, } for _, e := range examples { diff --git a/unstable/parser.go b/unstable/parser.go index e2c973b5..d97dc343 100644 --- a/unstable/parser.go +++ b/unstable/parser.go @@ -345,7 +345,7 @@ func (p *Parser) parseKeyval(b []byte) (reference, []byte, error) { b = p.parseWhitespace(b) if len(b) == 0 { - return invalidReference, nil, NewParserError(b, "expected = after a key, but the document ends there") + return invalidReference, nil, NewParserError(startB[:len(startB)-len(b)], "expected = after a key, but the document ends there") } b, err = expect('=', b)