refactor(utils): char-safe string truncation across tool_notifier, rag, query_rewriter#30
Conversation
…ng Rust primitive; fix rag test assertion to use chars().count(); add zero-max edge case test Co-authored-by: chinkan <16433287+chinkan@users.noreply.github.com> Agent-Logs-Url: https://github.com/chinkan/RustFox/sessions/df38c695-4336-437e-8324-5b6db9d2c378
|
Claude finished @chinkan's task in 1m 14s —— View job Code Review
Overall: This is a well-scoped, correct fix. The implementation is sound and the test coverage is thorough. A few minor observations below.
|
4229788
into
claude/chat-history-rag-telegram-T4Jmo
Byte-indexed slicing (
&s[..N]) panics when the byte boundary falls inside a multi-byte UTF-8 character. Three call sites in the codebase used this pattern with fixed offsets (60, 200, 300), making them crash-prone on any Chinese/Japanese/emoji input.Changes
src/utils/strings.rs(new) — sharedtruncate_chars(s, max_chars)helper that walks.chars()to find the safe byte boundary before slicing; namedstrings(notstr) to avoid shadowing the Rust primitivesrc/platform/tool_notifier.rs,src/memory/rag.rs,src/memory/query_rewriter.rs— replaced all three&s[..N]truncation sites withtruncate_charsrag.rstest — fixed assertion fromsnippet.len() == 303tosnippet.chars().count() == 303; the byte-length equality only holds for ASCIImax_chars=0edge case documented inutils/strings📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.