storkit: merge 437_bug_strip_prefix_ci_panics_on_multi_byte_utf_8_input

This commit is contained in:
dave
2026-03-28 16:30:44 +00:00
parent 77ff0ce093
commit 08db28d9d6
8 changed files with 28 additions and 32 deletions
+14 -4
View File
@@ -254,10 +254,8 @@ fn strip_mention<'a>(message: &'a str, bot_name: &str, bot_user_id: &str) -> &'a
}
fn strip_prefix_ci<'a>(text: &'a str, prefix: &str) -> Option<&'a str> {
if text.len() < prefix.len() {
return None;
}
if !text[..prefix.len()].eq_ignore_ascii_case(prefix) {
let candidate = text.get(..prefix.len())?;
if !candidate.eq_ignore_ascii_case(prefix) {
return None;
}
let rest = &text[prefix.len()..];
@@ -354,6 +352,18 @@ mod tests {
assert_eq!(cmd, None);
}
#[test]
fn extract_assign_command_multibyte_prefix_no_panic() {
// "xxxx⏺ assign 42 opus" — ⏺ (U+23FA) is 3 bytes, starting at byte 4.
// "@timmy" has len 6 so text[..6] lands inside ⏺ — panics without the fix.
let cmd = extract_assign_command(
"xxxx\u{23FA} assign 42 opus",
"Timmy",
"@timmy:home.local",
);
assert_eq!(cmd, None);
}
// -- resolve_agent_name --------------------------------------------------
#[test]