diff --git a/src/message_correct.rs b/src/message_correct.rs index 35494f81..8ce747f1 100644 --- a/src/message_correct.rs +++ b/src/message_correct.rs @@ -27,6 +27,11 @@ impl TryFrom for Replace { for _ in elem.children() { return Err(Error::ParseError("Unknown child in replace element.")); } + for (attr, _) in elem.attrs() { + if attr != "id" { + return Err(Error::ParseError("Unknown attribute in replace element.")); + } + } let id = get_attr!(elem, "id", required); Ok(Replace { id }) } @@ -36,7 +41,7 @@ impl Into for Replace { fn into(self) -> Element { Element::builder("replace") .ns(ns::MESSAGE_CORRECT) - .attr("id", self.id.clone()) + .attr("id", self.id) .build() } } @@ -51,6 +56,17 @@ mod tests { Replace::try_from(elem).unwrap(); } + #[test] + fn test_invalid_attribute() { + let elem: Element = "".parse().unwrap(); + let error = Replace::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Unknown attribute in replace element."); + } + #[test] fn test_invalid_child() { let elem: Element = "".parse().unwrap();