aboutsummaryrefslogtreecommitdiff
path: root/src/ext/framework
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-12-18 15:31:12 -0800
committerAustin Hellyer <[email protected]>2016-12-18 15:31:12 -0800
commitc01f238a34ad846f8732c8bf97fbbd96fbf6a7ae (patch)
treea81df9a7ceb9df8abd2515b8f453dd1962b488b6 /src/ext/framework
parentFix Message::delete() (diff)
downloadserenity-c01f238a34ad846f8732c8bf97fbbd96fbf6a7ae.tar.xz
serenity-c01f238a34ad846f8732c8bf97fbbd96fbf6a7ae.zip
Fix framework message position boundary splits
The framework would take the length of the prefix in bytes, and then search for a command either directly after the byte length _and_ plus one for a command. Instead, ensure that the message is longer than the prefix.
Diffstat (limited to 'src/ext/framework')
-rw-r--r--src/ext/framework/mod.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/ext/framework/mod.rs b/src/ext/framework/mod.rs
index 777736f..8047c20 100644
--- a/src/ext/framework/mod.rs
+++ b/src/ext/framework/mod.rs
@@ -284,36 +284,39 @@ impl Framework {
let res = command::positions(&context, &message.content, &self.configuration);
let positions = match res {
- Some(positions) => positions,
+ Some(mut positions) => {
+ // First, take out the prefixes that are as long as _or_ longer
+ // than the message, to avoid character boundary violations.
+ positions.retain(|p| *p < message.content.len());
+
+ // Ensure that there is _at least one_ position remaining. There
+ // is no point in continuing if there is not.
+ if positions.is_empty() {
+ return;
+ }
+
+ positions
+ },
None => return,
};
- // Ensure that the message length is at least longer than a prefix
- // length. There's no point in checking further ahead if there's nothing
- // _to_ check.
- if positions.iter().all(|p| message.content.len() <= *p) {
- return;
- }
-
'outer: for position in positions {
let mut built = String::new();
+ let round = message.content.chars()
+ .skip(position)
+ .collect::<String>();
+ let round = round.trim()
+ .split_whitespace()
+ .collect::<Vec<&str>>();
for i in 0..self.configuration.depth {
if i != 0 {
built.push(' ');
}
- built.push_str(match {
- message.content
- .split_at(position)
- .1
- .trim()
- .split_whitespace()
- .collect::<Vec<&str>>()
- .get(i)
- } {
+ built.push_str(match round.get(i) {
Some(piece) => piece,
- None => continue,
+ None => continue 'outer,
});
let groups = self.groups.clone();