Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect deserialization of triply-nested elements with a default namespace #200

Open
av-gal opened this issue Nov 5, 2024 · 0 comments

Comments

@av-gal
Copy link

av-gal commented Nov 5, 2024

I've encountered an issue with the yaserde_derive feature where a grandchild of the namespaced root node is not being deserialised. The child and grandchild nodes are both deserialised correctly when they are processed separately, without the root node as their ancestor.

Test case:

use yaserde::YaDeserialize;

#[derive(YaDeserialize, Debug, PartialEq)]
#[yaserde(rename = "EBMLSchema", namespace = "some_namespace")]
struct Schema {
  #[yaserde(rename = "element")]
  elements: Vec<Element>,
}

#[derive(YaDeserialize, Debug, PartialEq)]
#[yaserde(rename = "element")]
struct Element {
  #[yaserde(rename = "documentation")]
  documentation: Vec<Documentation>,
}

#[derive(YaDeserialize, Debug, PartialEq)]
#[yaserde(rename = "documentation")]
struct Documentation {
  #[yaserde(text)]
  body: String,
}

#[test]
fn nested_element_equality() {
  let parent = r#"<EBMLSchema xmlns="some_namespace">
<element>
<documentation>Test</documentation>
</element>
</EBMLSchema>"#;
  let parent: Schema = yaserde::de::from_str(parent).unwrap();

  let child = r#"<element>
<documentation>Test</documentation>
</element>"#;
  let child: Element = yaserde::de::from_str(child).unwrap();

  assert_eq!(parent.elements[0], child);
}

Output:

thread 'nested::nested_element_equality' panicked at examples\src\nested.rs:38:3:
assertion `left == right` failed
  left: Element { documentation: [] }
 right: Element { documentation: [Documentation { body: "Test" }] }
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/std\src\panicking.rs:662
   1: core::panicking::panic_fmt
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/core\src\panicking.rs:74
   2: core::panicking::assert_failed_inner
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/core\src\panicking.rs:412
   3: core::panicking::assert_failed<yaserde_examples::nested::Element,yaserde_examples::nested::Element>
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library\core\src\panicking.rs:367
   4: yaserde_examples::nested::nested_element_equality
             at .\src\nested.rs:38
   5: yaserde_examples::nested::nested_element_equality::closure$0
             at .\src\nested.rs:25
   6: core::ops::function::FnOnce::call_once<yaserde_examples::nested::nested_element_equality::closure_env$0,tuple$<> >
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library\core\src\ops\function.rs:250
   7: core::ops::function::FnOnce::call_once
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/core\src\ops\function.rs:250
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant