storkit: create 392_bug_strip_prefix_ci_panics_on_multi_byte_utf_8_characters

This commit is contained in:
dave
2026-03-25 13:55:49 +00:00
parent eef49678ce
commit dbd932bf46

View File

@@ -0,0 +1,27 @@
---
name: "strip_prefix_ci panics on multi-byte UTF-8 characters"
---
# Bug 392: strip_prefix_ci panics on multi-byte UTF-8 characters
## Description
strip_prefix_ci in matrix/commands/mod.rs panics when slicing text at a byte offset that falls inside a multi-byte UTF-8 character (e.g. right single quote ' is 3 bytes). This affects all transports (WhatsApp, Slack, Matrix) since they all share try_handle_command → strip_bot_mention → strip_prefix_ci. The panic occurs at line 234: text[..prefix.len()] when prefix.len() is not a char boundary in the input text.
## How to Reproduce
1. Send a message to the WhatsApp bot containing multi-byte UTF-8 characters (e.g. right single quotes or emojis) where the bot name prefix length lands inside a multi-byte character\n2. Example: "For now let's just deal with it" where the ' (right single quote, bytes 11..14) gets sliced at byte 12
## Actual Result
Thread panics: byte index 12 is not a char boundary; it is inside ''' (bytes 11..14)
## Expected Result
The function should handle multi-byte UTF-8 characters gracefully without panicking. If the prefix length doesn't fall on a char boundary, the text doesn't match the prefix — return None.
## Acceptance Criteria
- [ ] strip_prefix_ci checks text.is_char_boundary(prefix.len()) before slicing and returns None if not on a boundary
- [ ] Messages containing multi-byte UTF-8 characters (smart quotes, emojis, CJK, etc.) do not panic
- [ ] All transports (WhatsApp, Slack, Matrix) are covered since they share the same code path