From 984d479f2c1686c1bcfac44a2d0f23f8ba010b1b Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Sat, 18 Apr 2015 16:18:33 +0200 Subject: Fix CTCP recognition/make tests pass --- src/message.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/message.rs b/src/message.rs index 25e176c..50baaaf 100644 --- a/src/message.rs +++ b/src/message.rs @@ -41,8 +41,6 @@ impl<'a> FromStr for Message<'a> { let len = i.len(); let mut s = i; - let msg_type = if s.chars().next() == Some('\u{1}') { MsgType::Ctcp } else { MsgType::Irc }; - let prefix = if len >= 1 && s.chars().next() == Some(':') { s.find(' ').map(|i| { let p = s.slice_chars(1, i).to_owned(); @@ -75,6 +73,9 @@ impl<'a> FromStr for Message<'a> { if s.chars().next() == Some(' ') { s = &s[1..] }; } + let msg_type = if suffix.as_ref() + .and_then(|s| s.chars().next()) == Some('\u{1}') { MsgType::Ctcp } else { MsgType::Irc }; + command.map(move |c| Ok(Message::new(prefix.map(|p| Cow::Owned(p)), c.unwrap(), -- cgit v1.2.3