Skip to content

Commit 16b1ef5

Browse files
pelletierclaude
andauthored
Fix parser error pointing to wrong line when last line has no trailing newline (#1041)
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 Co-authored-by: Claude <[email protected]>
1 parent e14bde7 commit 16b1ef5

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

errors_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ func TestDecodeError_Position(t *testing.T) {
259259
expectedRow: 3,
260260
minCol: 5,
261261
},
262+
{
263+
name: "missing equals on last line without trailing newline",
264+
doc: "a = 1\nb = 2\nc",
265+
expectedRow: 3,
266+
minCol: 1,
267+
},
262268
}
263269

264270
for _, e := range examples {

unstable/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (p *Parser) parseKeyval(b []byte) (reference, []byte, error) {
345345
b = p.parseWhitespace(b)
346346

347347
if len(b) == 0 {
348-
return invalidReference, nil, NewParserError(b, "expected = after a key, but the document ends there")
348+
return invalidReference, nil, NewParserError(startB[:len(startB)-len(b)], "expected = after a key, but the document ends there")
349349
}
350350

351351
b, err = expect('=', b)

0 commit comments

Comments
 (0)