Skip to content

Commit

Permalink
Fix bug where nested structs with the same element names didn't deser…
Browse files Browse the repository at this point in the history
…ialzie properly.
  • Loading branch information
ephraimkunz committed May 5, 2021
1 parent fb19a35 commit 72d61e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
3 changes: 1 addition & 2 deletions yaserde/tests/deserializer.rs
Expand Up @@ -1052,6 +1052,5 @@ fn de_same_field_name_but_some_other_fields_or_something() {
};

serialize_and_validate!(model, content);
// TODO fix it
// deserialize_and_validate!(content, model, FooOuter);
deserialize_and_validate!(content, model, FooOuter);
}
27 changes: 17 additions & 10 deletions yaserde_derive/src/de/expand_struct.rs
Expand Up @@ -367,16 +367,23 @@ pub fn parse(
);
match event {
::xml::reader::XmlEvent::StartElement{ref name, ref attributes, ..} => {
match name.local_name.as_str() {
#call_visitors
_ => {
let event = reader.next_event()?;
#write_unused

if depth > 0 { // Don't skip root element
reader.skip_element(|event| {
#write_unused
})?;
if depth == 0 && name.local_name == #root {
// Consume root element. We must do this first. In the case it shares a name with a child element, we don't
// want to prematurely match the child element below.
let event = reader.next_event()?;
#write_unused
} else {
match name.local_name.as_str() {
#call_visitors
_ => {
let event = reader.next_event()?;
#write_unused

if depth > 0 { // Don't skip root element
reader.skip_element(|event| {
#write_unused
})?;
}
}
}
}
Expand Down

0 comments on commit 72d61e0

Please sign in to comment.