Skip to content

Commit 161e3d0

Browse files
author
Alex
committed
fix(agent): make sessions cluster truncation UTF-8 safe Refs #1734
Replace byte-index slicing ([..40], [..35]) with char-boundary-safe truncation using char_indices().take(n). Prevents panic on multibyte UTF-8 session titles and concept labels.
1 parent 976abf6 commit 161e3d0

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

crates/terraphim_agent/src/repl/handler.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,7 +2777,13 @@ impl ReplHandler {
27772777
for cluster in &clusters {
27782778
let concepts = cluster.dominant_concepts.join(", ");
27792779
let concepts_display = if concepts.len() > 40 {
2780-
format!("{}...", &concepts[..40])
2780+
let end = concepts
2781+
.char_indices()
2782+
.take(40)
2783+
.last()
2784+
.map(|(i, _)| i)
2785+
.unwrap_or(concepts.len());
2786+
format!("{}...", &concepts[..end])
27812787
} else {
27822788
concepts
27832789
};
@@ -2787,7 +2793,13 @@ impl ReplHandler {
27872793
.and_then(|s| s.title.as_ref())
27882794
.map(|t| {
27892795
if t.len() > 35 {
2790-
format!("{}...", &t[..35])
2796+
let end = t
2797+
.char_indices()
2798+
.take(35)
2799+
.last()
2800+
.map(|(i, _)| i)
2801+
.unwrap_or(t.len());
2802+
format!("{}...", &t[..end])
27912803
} else {
27922804
t.clone()
27932805
}

0 commit comments

Comments
 (0)