From 37481fb8f6cef4a16ace191a37412d57017b84d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Sun, 28 Apr 2024 10:48:35 +0200 Subject: [PATCH] parsers: do not do extensive XEP-0030 validation with disable-validation Other additional checks are already gated by the absence of this feature. As the MR to remove these checks altogether is still blocked, this should serve as at least as an intermediate solution to anyone affected by buggy remote implementations. --- parsers/src/disco.rs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/parsers/src/disco.rs b/parsers/src/disco.rs index dc23b62..18fa9af 100644 --- a/parsers/src/disco.rs +++ b/parsers/src/disco.rs @@ -151,22 +151,25 @@ impl TryFrom for DiscoInfoResult { } } - if result.identities.is_empty() { - return Err(Error::ParseError( - "There must be at least one identity in disco#info.", - )); - } - if result.features.is_empty() { - return Err(Error::ParseError( - "There must be at least one feature in disco#info.", - )); - } - if !result.features.contains(&Feature { - var: ns::DISCO_INFO.to_owned(), - }) { - return Err(Error::ParseError( - "disco#info feature not present in disco#info.", - )); + #[cfg(not(feature = "disable-validation"))] + { + if result.identities.is_empty() { + return Err(Error::ParseError( + "There must be at least one identity in disco#info.", + )); + } + if result.features.is_empty() { + return Err(Error::ParseError( + "There must be at least one feature in disco#info.", + )); + } + if !result.features.contains(&Feature { + var: ns::DISCO_INFO.to_owned(), + }) { + return Err(Error::ParseError( + "disco#info feature not present in disco#info.", + )); + } } Ok(result)