Skip to content

Commit 9b13828

Browse files
committed
fix(notifications): use safe UTF-8 slicing for session IDs
1 parent 912acd7 commit 9b13828

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cortex-cli/src/utils/notification.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ pub fn send_task_notification(session_id: &str, success: bool) -> Result<()> {
6363
"Cortex Task Failed"
6464
};
6565

66-
let short_id = &session_id[..8.min(session_id.len())];
66+
// Use safe UTF-8 slicing - find the last valid char boundary at or before position 8
67+
let short_id = session_id
68+
.char_indices()
69+
.take_while(|(idx, _)| *idx < 8)
70+
.map(|(idx, ch)| idx + ch.len_utf8())
71+
.last()
72+
.and_then(|end| session_id.get(..end))
73+
.unwrap_or(session_id);
6774
let body = format!("Session: {}", short_id);
6875

6976
let urgency = if success {

0 commit comments

Comments
 (0)