From 5206c59657d3a8f197735b747abf0ae3685a0cea Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Sat, 18 Apr 2015 17:40:46 +0200 Subject: Strip \r\n for easier processing --- .gitignore | 1 + src/message.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 245f0b7..6273b01 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ Session.vim *.so *.rlib *.dll +Cargo.lock # Executables *.exe diff --git a/src/message.rs b/src/message.rs index 31bd8a7..1765176 100644 --- a/src/message.rs +++ b/src/message.rs @@ -81,9 +81,10 @@ impl<'a> FromStr for Message<'a> { c.unwrap(), content, // strip \{1} if CTCP message + // strip \r\n for each line, relying on their existence match msg_type { - MsgType::Irc => suffix.map(Cow::Owned), - MsgType::Ctcp => suffix.map(|s| s[1..s.len() - 1].to_string()).map(Cow::Owned) + MsgType::Irc => suffix.map(|s| s[0..s.len() - 2].to_string()).map(Cow::Owned), + MsgType::Ctcp => suffix.map(|s| s[1..s.len() - 3].to_string()).map(Cow::Owned) }, msg_type )) @@ -116,6 +117,7 @@ impl<'a> ToString for Message<'a> { if let MsgType::Ctcp = self.msg_type { s.push('\u{1}') } } + s.push_str("\r\n"); s } } @@ -1186,7 +1188,7 @@ mod test { #[test] fn parse_message() { - let a = ":a.b.c NOTICE AUTH :*** Looking up your hostname..."; + let a = ":a.b.c NOTICE AUTH :*** Looking up your hostname...\r\n"; // I'm not even kidding... let a2 = Message::new( Some(Cow::Owned("a.b.c".to_owned())), @@ -1198,7 +1200,7 @@ mod test { assert_eq!(a.parse::().unwrap(), a2.clone()); assert_eq!(a2.to_string(), a); - let b = ":d PRIVMSG You :\u{1}ACTION sends you funny pictures of cats!\u{1}"; + let b = ":d PRIVMSG You :\u{1}ACTION sends you funny pictures of cats!\u{1}\r\n"; let b2 = Message::new( Some(Cow::Owned("d".to_owned())), Cow::Owned("PRIVMSG".to_owned()), -- cgit v1.2.3