From aaf5013407fb3d9ae1c3346bcfa88504d2e36b83 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Mon, 9 Mar 2015 22:06:43 -0400 Subject: [PATCH] Updated parsing to support colons within arguments. --- src/client/data/message.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/client/data/message.rs b/src/client/data/message.rs index 3bf9935..3506b70 100644 --- a/src/client/data/message.rs +++ b/src/client/data/message.rs @@ -83,9 +83,9 @@ impl FromStr for Message { } else { None }; - let suffix = if state.contains(":") { - let suffix = state.find(':').map(|i| &state[i+1..state.len()-2]); - state = state.find(':').map_or("", |i| &state[..i]); + let suffix = if state.contains(" :") { + let suffix = state.find(" :").map(|i| &state[i+2..state.len()-2]); + state = state.find(" :").map_or("", |i| &state[..i+1]); suffix } else { None @@ -196,6 +196,19 @@ mod test { assert_eq!(":test!test@test PRIVMSG test :Still testing!\r\n".to_message(), message); } + #[test] + fn to_message_with_colon_in_arg() { + // Apparently, UnrealIRCd (and perhaps some others) send some messages that include + // colons within individual parameters. So, let's make sure it parses correctly. + let message = Message { + prefix: Some(format!("test!test@test")), + command: format!("COMMAND"), + args: vec![format!("ARG:test")], + suffix: Some(format!("Still testing!")), + }; + assert_eq!(":test!test@test COMMAND ARG:test :Still testing!\r\n".to_message(), message); + } + #[test] #[should_fail] fn to_message_invalid_format() {