diff --git a/parsers/Cargo.toml b/parsers/Cargo.toml index b88de169..2daac1c0 100644 --- a/parsers/Cargo.toml +++ b/parsers/Cargo.toml @@ -32,8 +32,8 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] } [features] # Build xmpp-parsers to make components instead of clients. component = [] -# Disable validation of unknown attributes. -disable-validation = [ "xso/non-pedantic" ] +# Raise errors on unexpected children and attributes. +pedantic = [ "xso/pedantic" ] # Enable serde support in jid crate serde = [ "jid/serde" ] # Enable some additional logging in helpers diff --git a/parsers/ChangeLog b/parsers/ChangeLog index 372dd640..89a4c449 100644 --- a/parsers/ChangeLog +++ b/parsers/ChangeLog @@ -18,6 +18,10 @@ XXXX-YY-ZZ RELEASER - bind::BindFeature::required is now a bool, thanks to xso’s flag. - jingle_rtp::Description::rtcp_mux is now a bool flag too. - stream_limits::Limits now extract directly to NonZeroU32. + - Removed the `disable-validation` feature and made the behaviour the + new default. That way, unknown child elements and attributes will + not be rejected by xmpp-parsers by default anymore. The `pedantic` + feature can be used to opt into the previous default behaviour. * Improvements: - Make Priority’s inner i8 pub, which had been broken since the conversion to xso. (!632) diff --git a/parsers/src/attention.rs b/parsers/src/attention.rs index 00a32d14..a5880734 100644 --- a/parsers/src/attention.rs +++ b/parsers/src/attention.rs @@ -19,7 +19,7 @@ impl MessagePayload for Attention {} mod tests { use super::*; use minidom::Element; - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] use xso::error::{Error, FromElementError}; #[test] @@ -33,7 +33,7 @@ mod tests { Attention::try_from(elem).unwrap(); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_child() { let elem: Element = "" @@ -47,7 +47,7 @@ mod tests { assert_eq!(message, "Unknown child in Attention element."); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/parsers/src/avatar.rs b/parsers/src/avatar.rs index 3d8925fb..0bae402c 100644 --- a/parsers/src/avatar.rs +++ b/parsers/src/avatar.rs @@ -69,7 +69,7 @@ mod tests { use super::*; use crate::hashes::Algo; use minidom::Element; - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] use xso::error::{Error, FromElementError}; #[cfg(target_pointer_width = "32")] @@ -121,7 +121,7 @@ mod tests { assert_eq!(data.data, b"\0\0\0"); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid() { let elem: Element = "" diff --git a/parsers/src/bind.rs b/parsers/src/bind.rs index 47826e21..7d4d7012 100644 --- a/parsers/src/bind.rs +++ b/parsers/src/bind.rs @@ -72,7 +72,7 @@ impl From for Jid { mod tests { use super::*; use minidom::Element; - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] use xso::error::{Error, FromElementError}; #[cfg(target_pointer_width = "32")] @@ -118,7 +118,7 @@ mod tests { ); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_resource() { let elem: Element = "resource" diff --git a/parsers/src/blocking.rs b/parsers/src/blocking.rs index 897f8657..79328317 100644 --- a/parsers/src/blocking.rs +++ b/parsers/src/blocking.rs @@ -62,7 +62,7 @@ pub struct Blocked; #[cfg(test)] mod tests { - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] use xso::error::{Error, FromElementError}; use super::*; @@ -126,7 +126,7 @@ mod tests { assert_eq!(unblock.items, two_items); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid() { let elem: Element = "" @@ -169,7 +169,7 @@ mod tests { assert_eq!(message, "Unknown attribute in Unblock element."); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_non_empty_blocklist_request() { let elem: Element = "".parse().unwrap(); diff --git a/parsers/src/bob.rs b/parsers/src/bob.rs index 67594d87..634cae82 100644 --- a/parsers/src/bob.rs +++ b/parsers/src/bob.rs @@ -187,7 +187,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn unknown_child() { let elem: Element = "" .parse() diff --git a/parsers/src/caps.rs b/parsers/src/caps.rs index 05a3b405..fdff654b 100644 --- a/parsers/src/caps.rs +++ b/parsers/src/caps.rs @@ -197,7 +197,7 @@ mod tests { use super::*; use crate::caps; use minidom::Element; - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] use xso::error::{Error, FromElementError}; #[cfg(target_pointer_width = "32")] @@ -226,7 +226,7 @@ mod tests { ); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_child() { let elem: Element = "K1Njy3HZBThlo4moOD5gBGhn0U0oK7/CbfLlIUDi6o4=".parse().unwrap(); diff --git a/parsers/src/chatstates.rs b/parsers/src/chatstates.rs index dbe2b3a1..9ccae55c 100644 --- a/parsers/src/chatstates.rs +++ b/parsers/src/chatstates.rs @@ -70,7 +70,7 @@ mod tests { assert_eq!(message, "This is not a ChatState element."); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_child() { let elem: Element = "" @@ -84,7 +84,7 @@ mod tests { assert_eq!(message, "Unknown child in ChatState::Gone element."); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_attribute() { let elem: Element = "" diff --git a/parsers/src/data_forms.rs b/parsers/src/data_forms.rs index 9ebcd171..d5dcd278 100644 --- a/parsers/src/data_forms.rs +++ b/parsers/src/data_forms.rs @@ -485,7 +485,7 @@ mod tests { } #[test] - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] fn test_wrong_child() { let elem: Element = "" .parse() diff --git a/parsers/src/data_forms_validate.rs b/parsers/src/data_forms_validate.rs index ddfb5782..5d4a9a7b 100644 --- a/parsers/src/data_forms_validate.rs +++ b/parsers/src/data_forms_validate.rs @@ -449,7 +449,7 @@ mod tests { #[test] #[cfg_attr( - feature = "disable-validation", + not(feature = "pedantic"), should_panic = "Validate::try_from(element).is_err()" )] fn test_fails_with_invalid_children() { diff --git a/parsers/src/delay.rs b/parsers/src/delay.rs index 4d8e31c3..5800fdea 100644 --- a/parsers/src/delay.rs +++ b/parsers/src/delay.rs @@ -81,7 +81,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child() { let elem: Element = "" diff --git a/parsers/src/disco.rs b/parsers/src/disco.rs index ff704743..abcd8d9c 100644 --- a/parsers/src/disco.rs +++ b/parsers/src/disco.rs @@ -241,7 +241,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid() { let elem: Element = "" diff --git a/parsers/src/ecaps2.rs b/parsers/src/ecaps2.rs index 7669db39..acb2d58e 100644 --- a/parsers/src/ecaps2.rs +++ b/parsers/src/ecaps2.rs @@ -233,7 +233,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child() { let elem: Element = "K1Njy3HZBThlo4moOD5gBGhn0U0oK7/CbfLlIUDi6o4=+sDTQqBmX6iG/X3zjt06fjZMBBqL/723knFIyRf0sg8=".parse().unwrap(); let error = ECaps2::try_from(elem).unwrap_err(); diff --git a/parsers/src/eme.rs b/parsers/src/eme.rs index ca75d0d0..2b3388c8 100644 --- a/parsers/src/eme.rs +++ b/parsers/src/eme.rs @@ -72,7 +72,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child() { let elem: Element = "" diff --git a/parsers/src/forwarding.rs b/parsers/src/forwarding.rs index 0e3e557f..b5b8a775 100644 --- a/parsers/src/forwarding.rs +++ b/parsers/src/forwarding.rs @@ -58,7 +58,7 @@ mod tests { #[test] #[cfg(not(feature = "component"))] // feature = "component" changes namespace - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child() { let elem: Element = "" .parse() diff --git a/parsers/src/hashes.rs b/parsers/src/hashes.rs index 0febefc0..f116a481 100644 --- a/parsers/src/hashes.rs +++ b/parsers/src/hashes.rs @@ -305,7 +305,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child() { let elem: Element = "" .parse() diff --git a/parsers/src/idle.rs b/parsers/src/idle.rs index 10d5461b..b59ba5e8 100644 --- a/parsers/src/idle.rs +++ b/parsers/src/idle.rs @@ -42,7 +42,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child() { let elem: Element = "" diff --git a/parsers/src/jingle.rs b/parsers/src/jingle.rs index fd529286..08116866 100644 --- a/parsers/src/jingle.rs +++ b/parsers/src/jingle.rs @@ -770,7 +770,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child_in_reason() { let elem: Element = "".parse().unwrap(); let error = Jingle::try_from(elem).unwrap_err(); diff --git a/parsers/src/jingle_ft.rs b/parsers/src/jingle_ft.rs index 0eecf8a9..84e61002 100644 --- a/parsers/src/jingle_ft.rs +++ b/parsers/src/jingle_ft.rs @@ -316,7 +316,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_received_unknown_child() { let elem: Element = "".parse().unwrap(); let error = Received::try_from(elem).unwrap_err(); @@ -358,7 +358,7 @@ mod tests { ); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_received() { let elem: Element = "".parse().unwrap(); @@ -401,7 +401,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_checksum_unknown_child() { let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); let error = Checksum::try_from(elem).unwrap_err(); @@ -440,7 +440,7 @@ mod tests { ); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_checksum() { let elem: Element = "w0mcJylzCn+AfvuGdqkty2+KP48=".parse().unwrap(); @@ -481,7 +481,7 @@ mod tests { assert_eq!(range2.hashes, hashes); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_range() { let elem: Element = "" diff --git a/parsers/src/mam.rs b/parsers/src/mam.rs index 84883e4b..ad4ed0a4 100644 --- a/parsers/src/mam.rs +++ b/parsers/src/mam.rs @@ -300,7 +300,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child() { let elem: Element = "" .parse() diff --git a/parsers/src/media_element.rs b/parsers/src/media_element.rs index 1a1b364e..5812c060 100644 --- a/parsers/src/media_element.rs +++ b/parsers/src/media_element.rs @@ -154,7 +154,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_unknown_child() { let elem: Element = "" .parse() diff --git a/parsers/src/message_correct.rs b/parsers/src/message_correct.rs index f954579f..76cffbd5 100644 --- a/parsers/src/message_correct.rs +++ b/parsers/src/message_correct.rs @@ -47,7 +47,7 @@ mod tests { Replace::try_from(elem).unwrap(); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_attribute() { let elem: Element = "" @@ -62,7 +62,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child() { let elem: Element = "" diff --git a/parsers/src/muc/muc.rs b/parsers/src/muc/muc.rs index d8b65639..105b8251 100644 --- a/parsers/src/muc/muc.rs +++ b/parsers/src/muc/muc.rs @@ -127,7 +127,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_muc_invalid_child() { let elem: Element = "" .parse() @@ -153,7 +153,7 @@ mod tests { assert_eq!(elem, elem2); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_muc_invalid_attribute() { let elem: Element = "" diff --git a/parsers/src/muc/user.rs b/parsers/src/muc/user.rs index 4f15a7a9..d10b87ce 100644 --- a/parsers/src/muc/user.rs +++ b/parsers/src/muc/user.rs @@ -403,7 +403,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_invalid_child() { let elem: Element = " @@ -433,7 +433,7 @@ mod tests { assert_eq!(elem, elem2); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_invalid_attribute() { let elem: Element = "" @@ -468,7 +468,7 @@ mod tests { assert_eq!(message, "Required attribute 'code' missing."); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_status_invalid_child() { let elem: Element = " @@ -579,7 +579,7 @@ mod tests { } #[test] - #[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")] + #[cfg_attr(not(feature = "pedantic"), should_panic = "Result::unwrap_err")] fn test_continue_invalid() { let elem: Element = "" @@ -606,7 +606,7 @@ mod tests { assert_eq!(elem2, elem3); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_reason_invalid_attribute() { let elem: Element = "" @@ -620,7 +620,7 @@ mod tests { assert_eq!(message, "Unknown attribute in Reason element.".to_owned()); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_reason_invalid() { let elem: Element = " @@ -636,7 +636,7 @@ mod tests { assert_eq!(message, "Unknown child in Reason element.".to_owned()); } - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] #[test] fn test_item_invalid_attr() { let elem: Element = " { - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] for _ in $elem.children() { return Err(xso::error::Error::Other( concat!("Unknown child in ", $name, " element.").into(), @@ -330,7 +330,7 @@ macro_rules! check_no_children { macro_rules! check_no_attributes { ($elem:ident, $name:tt) => { - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] for _ in $elem.attrs() { return Err(xso::error::Error::Other( concat!("Unknown attribute in ", $name, " element.").into(), @@ -342,7 +342,7 @@ macro_rules! check_no_attributes { macro_rules! check_no_unknown_attributes { ($elem:ident, $name:tt, [$($attr:tt),*]) => ( - #[cfg(not(feature = "disable-validation"))] + #[cfg(feature = "pedantic")] for ((ns, attr), _) in $elem.attrs() { $( if *ns == ::xso::exports::rxml::Namespace::NONE && attr == $attr { diff --git a/tokio-xmpp/Cargo.toml b/tokio-xmpp/Cargo.toml index 3aa6f589..02a2232b 100644 --- a/tokio-xmpp/Cargo.toml +++ b/tokio-xmpp/Cargo.toml @@ -90,7 +90,7 @@ serde = [ "xmpp-parsers/serde" ] dns = [ "hickory-resolver", "idna" ] component = ["xmpp-parsers/component", "insecure-tcp"] -disable-validation = ["xmpp-parsers/disable-validation"] +pedantic = ["xmpp-parsers/pedantic"] [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(xmpprs_doc_build)'] } diff --git a/tokio-xmpp/ChangeLog b/tokio-xmpp/ChangeLog index 262a0dbf..63020a6d 100644 --- a/tokio-xmpp/ChangeLog +++ b/tokio-xmpp/ChangeLog @@ -1,5 +1,10 @@ Version NEXT: 0000-00-00 RELEASER + * Breaking: + - Removed the `disable-validation` feature and made the behaviour the + new default. The newly-introduced `pedantic` feature can be used to + opt into the previous default behaviour of rejecting all unknown + child elements and attributes. * Added: - Expose `client_auth` method to allow manual stream setups for advanced use cases. diff --git a/xso/Cargo.toml b/xso/Cargo.toml index 1b629973..95a44de1 100644 --- a/xso/Cargo.toml +++ b/xso/Cargo.toml @@ -31,7 +31,7 @@ default = [ "std" ] macros = [ "dep:xso_proc", "rxml/macros" ] minidom = [ "xso_proc/minidom"] panicking-into-impl = ["xso_proc/panicking-into-impl"] -non-pedantic = [] +pedantic = [] std = [] [package.metadata.docs.rs] diff --git a/xso/ChangeLog b/xso/ChangeLog index 2cd18a79..3ca914a1 100644 --- a/xso/ChangeLog +++ b/xso/ChangeLog @@ -1,4 +1,8 @@ Version NEXT: + * Breaking + - Removed the `non-pedantic` feature and made the behaviour the default. + - Added the `pedantic` feature, opting into the previous default + behaviour of rejecting unknown attributes and children. * Changes - Fix some Clippy warnings - Fix build with minidom and without std (!661) diff --git a/xso/src/lib.rs b/xso/src/lib.rs index 6a16e033..a2eb3fdd 100644 --- a/xso/src/lib.rs +++ b/xso/src/lib.rs @@ -349,17 +349,17 @@ pub trait AsOptionalXmlText { pub enum UnknownAttributePolicy { /// All unknown attributes are discarded. /// - /// This is the default policy if the crate is built with the - /// `non-pedantic` feature. - #[cfg_attr(feature = "non-pedantic", default)] + /// This is the default policy if the crate is built without the + /// `pedantic` feature. + #[cfg_attr(not(feature = "pedantic"), default)] Discard, /// The first unknown attribute which is encountered generates a fatal /// parsing error. /// - /// This is the default policy if the crate is built **without** the - /// `non-pedantic` feature. - #[cfg_attr(not(feature = "non-pedantic"), default)] + /// This is the default policy if the crate is built with the + /// `pedantic` feature. + #[cfg_attr(feature = "pedantic", default)] Fail, } @@ -386,17 +386,17 @@ impl UnknownAttributePolicy { pub enum UnknownChildPolicy { /// All unknown children are discarded. /// - /// This is the default policy if the crate is built with the - /// `non-pedantic` feature. - #[cfg_attr(feature = "non-pedantic", default)] + /// This is the default policy if the crate is built without the + /// `pedantic` feature. + #[cfg_attr(not(feature = "pedantic"), default)] Discard, /// The first unknown child which is encountered generates a fatal /// parsing error. /// - /// This is the default policy if the crate is built **without** the - /// `non-pedantic` feature. - #[cfg_attr(not(feature = "non-pedantic"), default)] + /// This is the default policy if the crate is built with the + /// `pedantic` feature. + #[cfg_attr(feature = "pedantic", default)] Fail, }