Skip to content

Commit 5776f94

Browse files
committed
fix: use rune-based truncation in truncateString to handle multibyte characters
1 parent fb76d52 commit 5776f94

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

cmd/root.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,16 @@ func completeStartPoint(ctx context.Context) ([]string, cobra.ShellCompDirective
445445
return completions, cobra.ShellCompDirectiveNoFileComp
446446
}
447447

448-
// truncateString truncates a string to maxLen characters, adding "..." if truncated.
448+
// truncateString truncates a string to maxLen runes, adding "..." if truncated.
449449
func truncateString(s string, maxLen int) string {
450-
if len(s) <= maxLen {
450+
r := []rune(s)
451+
if len(r) <= maxLen {
451452
return s
452453
}
453454
if maxLen <= 3 {
454-
return s[:maxLen]
455+
return string(r[:maxLen])
455456
}
456-
return s[:maxLen-3] + "..."
457+
return string(r[:maxLen-3]) + "..."
457458
}
458459

459460
func listWorktrees(ctx context.Context) error {

0 commit comments

Comments
 (0)