xmpp_parsers: --features disable-validation

It was broken in multiple ways:

- xso did not honour it: unknown children and attributes would cause a
  parse error even with `--features disable-validation` set on parsers.
  For this, we introduce a new feature flag on xso, `non-pedantic`,
  which defaults unknown children and attributes to discard instead of
  fail.

  Note that individual XSOs can still choose to be always pedantic or
  always lenient by explicitly declaring the intent via the
  `on_unknown_child` and `on_unknown_attribute` metas.

- Many tests in `xmpp_parsers` were broken with `--features
  disable-validation`. They now all pass while *still* being rn with
  `disable-validation` set: In that case, they test that parsing in fact
  succeeds.
This commit is contained in:
Jonas Schäfer 2024-12-20 08:57:46 +01:00
commit b8af0d8fa2
25 changed files with 104 additions and 24 deletions

View file

@ -289,7 +289,7 @@ mod tests {
}
#[test]
fn test_invalid_item() {
fn test_item_missing_jid() {
let elem: Element = "<query xmlns='jabber:iq:roster'><item/></query>"
.parse()
.unwrap();
@ -302,7 +302,10 @@ mod tests {
message,
"Required attribute field 'jid' on Item element missing."
);
}
#[test]
fn test_item_invalid_jid() {
let elem: Element = "<query xmlns='jabber:iq:roster'><item jid=''/></query>"
.parse()
.unwrap();
@ -311,7 +314,11 @@ mod tests {
format!("{error}"),
"text parse error: no domain found in this JID"
);
}
#[test]
#[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")]
fn test_item_unknown_child() {
let elem: Element =
"<query xmlns='jabber:iq:roster'><item jid='coucou'><coucou/></item></query>"
.parse()