Skip to content

Commit ea38df9

Browse files
committed
fix: diagnostic renderer byte-slices UTF-8 in truncation
line[:117] slices by byte offset, which can cut mid-character for multi-byte UTF-8 strings. Convert to []rune before truncating to ensure clean character boundaries.
1 parent abce025 commit ea38df9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

core/diagnostic_render.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,10 @@ func (r *DiagnosticRenderer) renderSourceLine(lines []string, lineIdx, lineNum,
171171
}
172172

173173
line := lines[lineIdx]
174-
// Truncate long lines
175-
if len(line) > 120 {
176-
line = line[:117] + "..."
174+
// Truncate long lines (use runes to avoid splitting multi-byte UTF-8 characters)
175+
runes := []rune(line)
176+
if len(runes) > 120 {
177+
line = string(runes[:117]) + "..."
177178
}
178179

179180
gutter := fmt.Sprintf("%*d", gutterWidth, lineNum)

0 commit comments

Comments
 (0)