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 <noreply@anthropic.com>
This commit is contained in:
@@ -259,6 +259,12 @@ func TestDecodeError_Position(t *testing.T) {
|
|||||||
expectedRow: 3,
|
expectedRow: 3,
|
||||||
minCol: 5,
|
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 {
|
for _, e := range examples {
|
||||||
|
|||||||
+1
-1
@@ -345,7 +345,7 @@ func (p *Parser) parseKeyval(b []byte) (reference, []byte, error) {
|
|||||||
b = p.parseWhitespace(b)
|
b = p.parseWhitespace(b)
|
||||||
|
|
||||||
if len(b) == 0 {
|
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)
|
b, err = expect('=', b)
|
||||||
|
|||||||
Reference in New Issue
Block a user