pubsub/event: Remove invalid empty items.

This commit is contained in:
Emmanuel Gil Peyrot 2018-08-02 22:06:34 +02:00
parent 679dd14a49
commit 89efc89423

View file

@ -69,9 +69,6 @@ pub enum PubSubEvent {
node: NodeName, node: NodeName,
redirect: Option<String>, redirect: Option<String>,
}, },
EmptyItems {
node: NodeName,
},
PublishedItems { PublishedItems {
node: NodeName, node: NodeName,
items: Vec<Item>, items: Vec<Item>,
@ -119,9 +116,9 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
} }
} }
Ok(match is_retract { Ok(match is_retract {
None => PubSubEvent::EmptyItems { node },
Some(false) => PubSubEvent::PublishedItems { node, items }, Some(false) => PubSubEvent::PublishedItems { node, items },
Some(true) => PubSubEvent::RetractedItems { node, items: retracts }, Some(true) => PubSubEvent::RetractedItems { node, items: retracts },
None => return Err(Error::ParseError("Missing children in items element.")),
}) })
} }
@ -204,12 +201,6 @@ impl From<PubSubEvent> for Element {
})) }))
.build() .build()
}, },
PubSubEvent::EmptyItems { node } => {
Element::builder("items")
.ns(ns::PUBSUB_EVENT)
.attr("node", node)
.build()
},
PubSubEvent::PublishedItems { node, items } => { PubSubEvent::PublishedItems { node, items } => {
Element::builder("items") Element::builder("items")
.ns(ns::PUBSUB_EVENT) .ns(ns::PUBSUB_EVENT)
@ -260,13 +251,14 @@ mod tests {
use compare_elements::NamespaceAwareCompare; use compare_elements::NamespaceAwareCompare;
#[test] #[test]
fn test_simple() { fn missing_items() {
let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><items node='coucou'/></event>".parse().unwrap(); let elem: Element = "<event xmlns='http://jabber.org/protocol/pubsub#event'><items node='coucou'/></event>".parse().unwrap();
let event = PubSubEvent::try_from(elem).unwrap(); let error = PubSubEvent::try_from(elem).unwrap_err();
match event { let message = match error {
PubSubEvent::EmptyItems { node } => assert_eq!(node, NodeName(String::from("coucou"))), Error::ParseError(string) => string,
_ => panic!(), _ => panic!(),
} };
assert_eq!(message, "Missing children in items element.");
} }
#[test] #[test]