You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] [v0.0.7] truncate_text() in summarizer.rs panics on multi-byte UTF-8 due to byte-index slicing #186
The truncate_text function uses byte-index slicing (&text[..max_chars]) which can panic if max_chars falls in the middle of a multi-byte UTF-8 character.
When text contains multi-byte UTF-8 characters (like emojis, Chinese characters, etc.), using byte-index slicing &text[..max_chars] can panic at runtime if max_chars lands in the middle of a multi-byte character.
Expected Behavior
The function should use character-based truncation (similar to what's done in cortex-common/src/truncate.rs) instead of byte-index slicing.
Suggested Fix
Use the safe truncation functions from cortex_common::truncate module:
use cortex_common::truncate::truncate_with_ellipsis;fntruncate_text(text:&str,max_tokens:usize) -> String{let max_chars = max_tokens *4;truncate_with_ellipsis(text, max_chars).into_owned()}
Or implement character-based truncation inline using .chars().take().
Activity