tokio-xmpp: Prevent XmppCodec from producing invalid stanza
This bug was introduced by 2e97f4de2e
, to
fix another bug where the parser would choke on whitespace.
The bug would manifest whenever a stanza was sent in different parts,
for example:
<< "<message "
<< "type='chat><body>foo</body></message>"
Would produce the following once parsed:
`<messagetype='chat'><body>foo</body></messagetype='chat'>`
This commit ensures this doesn't happen anymore (by not trimming
whitespaces before feeding the parser), and also ensures that
whitespaces are now handled at the correct layer.
The removal of xmpp_codec::test_lone_whitespace only happens because I'm
not sure if it's supposed to be here anymore. Maybe it should be at a
different layer? Or written differently?
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
0377b5658a
commit
44eaa5a6ea
2 changed files with 6 additions and 5 deletions
|
@ -177,6 +177,7 @@ impl Stream for Client {
|
|||
}
|
||||
Ok(Async::Ready(Some(Packet::Text(_)))) => {
|
||||
// Ignore text between stanzas
|
||||
self.state = ClientState::Connected(stream);
|
||||
Ok(Async::NotReady)
|
||||
}
|
||||
Ok(Async::Ready(Some(Packet::StreamStart(_)))) => {
|
||||
|
|
|
@ -229,9 +229,8 @@ impl Decoder for XMPPCodec {
|
|||
};
|
||||
let buf1 = buf1.as_ref().as_ref();
|
||||
match from_utf8(buf1) {
|
||||
Ok(mut s) => {
|
||||
Ok(s) => {
|
||||
debug!("<< {:?}", s);
|
||||
s = s.trim();
|
||||
if !s.is_empty() {
|
||||
let mut buffer_queue = BufferQueue::new();
|
||||
let tendril = FromIterator::from_iter(s.chars());
|
||||
|
@ -503,7 +502,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_lone_whitespace() {
|
||||
fn test_cut_out_stanza() {
|
||||
let mut c = XMPPCodec::new();
|
||||
let mut b = BytesMut::with_capacity(1024);
|
||||
b.put(r"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
||||
|
@ -514,10 +513,11 @@ mod tests {
|
|||
});
|
||||
|
||||
b.clear();
|
||||
b.put(r" ");
|
||||
b.put(r"<message ");
|
||||
b.put(r"type='chat'><body>Foo</body></message>");
|
||||
let r = c.decode(&mut b);
|
||||
assert!(match r {
|
||||
Ok(None) => true,
|
||||
Ok(Some(Packet::Stanza(_))) => true,
|
||||
_ => false,
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue