From 0a6ee5b32e3db5b6f94b4ee472f82ddc9674ee8b Mon Sep 17 00:00:00 2001 From: xmppftw Date: Thu, 21 Dec 2023 20:48:57 +0100 Subject: [PATCH] Support legacy integer code. Don't expose it. --- parsers/src/stanza_error.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/parsers/src/stanza_error.rs b/parsers/src/stanza_error.rs index ec7ee764..2b53cd5e 100644 --- a/parsers/src/stanza_error.rs +++ b/parsers/src/stanza_error.rs @@ -245,7 +245,9 @@ impl TryFrom for StanzaError { fn try_from(elem: Element) -> Result { check_self!(elem, "error", DEFAULT_NS); - check_no_unknown_attributes!(elem, "error", ["type", "by"]); + // The code attribute has been deprecated in [XEP-0086](https://xmpp.org/extensions/xep-0086.html) + // which was deprecated in 2007. We don't error when it's here, but don't include it in the final struct. + check_no_unknown_attributes!(elem, "error", ["type", "by", "code"]); let mut stanza_error = StanzaError { type_: get_attr!(elem, "type", Required), @@ -388,4 +390,16 @@ mod tests { }; assert_eq!(message, "Error must have a defined-condition."); } + + #[test] + fn test_error_code() { + let elem: Element = r#" + + The feature requested is not implemented by the recipient or server and therefore cannot be processed. +"# + .parse() + .unwrap(); + let stanza_error = StanzaError::try_from(elem).unwrap(); + assert_eq!(stanza_error.type_, ErrorType::Cancel); + } }