From 10c56a9385c0d410241d33525f8f49242daced2d Mon Sep 17 00:00:00 2001 From: Uninteresting Account Date: Mon, 13 Nov 2017 22:41:11 +1000 Subject: [PATCH] Fix strange behaviour when the prefix has spaces (#215) --- src/framework/standard/command.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/framework/standard/command.rs b/src/framework/standard/command.rs index 14b77ba06c6..55a6dfd2a3a 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 { // 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 { - 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()) }