From 1ecfaeb2bf092d4a3c6296d94054e444117f7bd9 Mon Sep 17 00:00:00 2001 From: Paul Fariello Date: Tue, 27 Feb 2024 08:53:19 +0100 Subject: [PATCH] Fix multiple error text lang handling in stanza_error --- parsers/src/stanza_error.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/parsers/src/stanza_error.rs b/parsers/src/stanza_error.rs index 2b53cd5e..5cd46459 100644 --- a/parsers/src/stanza_error.rs +++ b/parsers/src/stanza_error.rs @@ -262,7 +262,7 @@ impl TryFrom for StanzaError { if child.is("text", ns::XMPP_STANZAS) { check_no_children!(child, "text"); check_no_unknown_attributes!(child, "text", ["xml:lang"]); - let lang = get_attr!(elem, "xml:lang", Default); + let lang = get_attr!(child, "xml:lang", Default); if stanza_error.texts.insert(lang, child.text()).is_some() { return Err(Error::ParseError( "Text element present twice for the same xml:lang.", @@ -396,6 +396,19 @@ mod tests { 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); + } + + #[test] + fn test_error_multiple_text() { + let elem: Element = r#" + + Nœud non trouvé + Node not found "# .parse() .unwrap();