diff options
| author | Uninteresting Account <[email protected]> | 2017-11-13 22:41:11 +1000 |
|---|---|---|
| committer | alex <[email protected]> | 2017-11-13 13:41:11 +0100 |
| commit | 10c56a9385c0d410241d33525f8f49242daced2d (patch) | |
| tree | fc5b8f30a92a32559f90fb0823d4fd9694985d5b /src/framework | |
| parent | Implement From<EmojiId | EmojiIdentifier> for ReactionType (#217) (diff) | |
| download | serenity-10c56a9385c0d410241d33525f8f49242daced2d.tar.xz serenity-10c56a9385c0d410241d33525f8f49242daced2d.zip | |
Fix strange behaviour when the prefix has spaces (#215)
Diffstat (limited to 'src/framework')
| -rw-r--r-- | src/framework/standard/command.rs | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs index 14b77ba..55a6dfd 100644 --- a/src/framework/standard/command.rs +++ b/src/framework/standard/command.rs @@ -203,20 +203,16 @@ fn find_mention_end(content: &str, conf: &Configuration) -> Option<usize> { // Finds the end of the first continuous block of whitespace after the prefix fn find_end_of_prefix_with_whitespace(content: &str, position: usize) -> Option<usize> { - let mut ws_split = content.split_whitespace(); - if let Some(cmd) = ws_split.nth(1) { - if let Some(index_of_cmd) = content.find(cmd) { - if index_of_cmd > position && index_of_cmd <= content.len() { - let slice = unsafe { content.slice_unchecked(position, index_of_cmd) }.as_bytes(); - for byte in slice.iter() { - // 0x20 is ASCII for space - if *byte != 0x20u8 { - return None; - } - } - return Some(index_of_cmd); - } + let content_len = content.len(); + if position >= content_len { return None; } + + let slice = unsafe { content.slice_unchecked(position, content_len) }.as_bytes(); + for i in 0..slice.len() { + match slice[i] { + // \t \n \r [space] + 0x09 | 0x0a | 0x0d | 0x20 => {} + _ => return if i == 0 { None } else { Some(position + i) } } } - None + Some(content.len()) } |