Skip to content

Commit

Permalink
Fix strange behaviour when the prefix has spaces (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uninteresting Account authored and arqunis committed Nov 13, 2017
1 parent 68156c9 commit 10c56a9
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/framework/standard/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 10c56a9

Please sign in to comment.