storkit: merge 437_bug_strip_prefix_ci_panics_on_multi_byte_utf_8_input
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user