diff --git a/src/xmpp_codec.rs b/src/xmpp_codec.rs index 0002087..654cc21 100644 --- a/src/xmpp_codec.rs +++ b/src/xmpp_codec.rs @@ -229,7 +229,8 @@ impl Decoder for XMPPCodec { }; let buf1 = buf1.as_ref().as_ref(); match from_utf8(buf1) { - Ok(s) => { + Ok(mut s) => { + s = s.trim(); if !s.is_empty() { // println!("<< {}", s); let mut buffer_queue = BufferQueue::new(); @@ -508,4 +509,24 @@ mod tests { &("".to_owned() + &text + "").as_bytes() ); } + + #[test] + fn test_lone_whitespace() { + let mut c = XMPPCodec::new(); + let mut b = BytesMut::with_capacity(1024); + b.put(r""); + let r = c.decode(&mut b); + assert!(match r { + Ok(Some(Packet::StreamStart(_))) => true, + _ => false, + }); + + b.clear(); + b.put(r" "); + let r = c.decode(&mut b); + assert!(match r { + Ok(None) => true, + _ => false, + }); + } }