Add a new check_no_attributes macro, to avoid the empty list.
This commit is contained in:
parent
1892e1ca04
commit
f85b451fcf
4 changed files with 13 additions and 7 deletions
|
@ -40,7 +40,7 @@ impl TryFrom<Element> for ChatState {
|
|||
fn try_from(elem: Element) -> Result<ChatState, Error> {
|
||||
check_ns_only!(elem, "chatstate", ns::CHATSTATES);
|
||||
check_no_children!(elem, "chatstate");
|
||||
check_no_unknown_attributes!(elem, "chatstate", []);
|
||||
check_no_attributes!(elem, "chatstate");
|
||||
Ok(match elem.name() {
|
||||
"active" => ChatState::Active,
|
||||
"composing" => ChatState::Composing,
|
||||
|
|
|
@ -105,14 +105,14 @@ impl TryFrom<Element> for Field {
|
|||
for element in elem.children() {
|
||||
if element.is("value", ns::DATA_FORMS) {
|
||||
check_no_children!(element, "value");
|
||||
check_no_unknown_attributes!(element, "value", []);
|
||||
check_no_attributes!(element, "value");
|
||||
field.values.push(element.text());
|
||||
} else if element.is("required", ns::DATA_FORMS) {
|
||||
if field.required {
|
||||
return Err(Error::ParseError("More than one required element."));
|
||||
}
|
||||
check_no_children!(element, "required");
|
||||
check_no_unknown_attributes!(element, "required", []);
|
||||
check_no_attributes!(element, "required");
|
||||
field.required = true;
|
||||
} else if element.is("option", ns::DATA_FORMS) {
|
||||
if !field.is_list() {
|
||||
|
@ -184,14 +184,14 @@ impl TryFrom<Element> for DataForm {
|
|||
return Err(Error::ParseError("More than one title in form element."));
|
||||
}
|
||||
check_no_children!(child, "title");
|
||||
check_no_unknown_attributes!(child, "title", []);
|
||||
check_no_attributes!(child, "title");
|
||||
form.title = Some(child.text());
|
||||
} else if child.is("instructions", ns::DATA_FORMS) {
|
||||
if form.instructions.is_some() {
|
||||
return Err(Error::ParseError("More than one instructions in form element."));
|
||||
}
|
||||
check_no_children!(child, "instructions");
|
||||
check_no_unknown_attributes!(child, "instructions", []);
|
||||
check_no_attributes!(child, "instructions");
|
||||
form.instructions = Some(child.text());
|
||||
} else if child.is("field", ns::DATA_FORMS) {
|
||||
let field = Field::try_from(child.clone())?;
|
||||
|
|
|
@ -154,6 +154,12 @@ macro_rules! check_no_children {
|
|||
);
|
||||
}
|
||||
|
||||
macro_rules! check_no_attributes {
|
||||
($elem:ident, $name:tt) => (
|
||||
check_no_unknown_attributes!($elem, $name, []);
|
||||
);
|
||||
}
|
||||
|
||||
macro_rules! check_no_unknown_attributes {
|
||||
($elem:ident, $name:tt, [$($attr:tt),*]) => (
|
||||
for (_attr, _) in $elem.attrs() {
|
||||
|
@ -182,7 +188,7 @@ macro_rules! generate_empty_element {
|
|||
fn try_from(elem: Element) -> Result<$elem, Error> {
|
||||
check_self!(elem, $name, $ns);
|
||||
check_no_children!(elem, $name);
|
||||
check_no_unknown_attributes!(elem, $name, []);
|
||||
check_no_attributes!(elem, $name);
|
||||
Ok($elem)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ impl TryFrom<Element> for PubSubEvent {
|
|||
|
||||
fn try_from(elem: Element) -> Result<PubSubEvent, Error> {
|
||||
check_self!(elem, "event", ns::PUBSUB_EVENT);
|
||||
check_no_unknown_attributes!(elem, "event", []);
|
||||
check_no_attributes!(elem, "event");
|
||||
|
||||
let mut payload = None;
|
||||
for child in elem.children() {
|
||||
|
|
Loading…
Reference in a new issue