From 9a96f78177b644039a719af82125b853266ba03a Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Sat, 8 Aug 2026 19:52:01 +0800 Subject: [PATCH] handlers: fix UTF-8 byte-slice panic in message log preview --- crates/xmedia-bot/src/handlers.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/xmedia-bot/src/handlers.rs b/crates/xmedia-bot/src/handlers.rs index 9765063..46ec0f4 100644 --- a/crates/xmedia-bot/src/handlers.rs +++ b/crates/xmedia-bot/src/handlers.rs @@ -673,7 +673,10 @@ pub async fn message_handler(bot: Bot, message: Message) -> Result<(), RequestEr .unwrap_or_else(|| "unknown".to_string()); let text_preview = message .text() - .map(|t| if t.len() > 120 { &t[..120] } else { t }) + .map(|t| { + let end = t.floor_char_boundary(120.min(t.len())); + &t[..end] + }) .unwrap_or(""); log::info!( "message from {sender} in {} (private={is_private}): {text_preview}",