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

wip: Strict deserialization returns error on any unknown xml field #194

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions yaserde/tests/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,3 +1117,20 @@ fn de_nested_macro_rules() {

float_attrs!(f32);
}

#[test]
fn de_strict() {
init();

#[derive(PartialEq, Debug, YaDeserialize)]
pub struct Struct {
id: i32,
}
let xml_content = r#"<?xml version="1.0" encoding="utf-8"?>
<Struct>
<id>123</id>
<NonExistentAttrShouldCrash></NonExistentAttrShouldCrash>
</Struct>"#;
let load: Result<Struct, String> = from_str(xml_content);
assert!(load.is_err());
}
3 changes: 3 additions & 0 deletions yaserde_derive/src/de/expand_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ pub fn parse(
match (namespace.as_str(), name.local_name.as_str()) {
#call_visitors
_ => {
::yaserde::__derive_trace!("SKIPPINGSKIPPING Skipping element {:?}", name.local_name);
return Err(format!("Found unauthorized element {}", name.local_name));

let event = reader.next_event()?;
#write_unused

Expand Down