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

deps: bump quick-xml dependency from 0.30 to 0.31 #21

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ required-features = ["derive", "i8", "nil"]
dxr_derive = { workspace = true, optional = true }
base64 = "0.22"
chrono = { version = "0.4.19", features = ["std"], default-features = false }
quick-xml = { version = "0.30", features = ["serialize"] }
quick-xml = { version = "0.31", features = ["serialize"] }
serde = { version = "1.0.104", features = ["derive"] }
thiserror = "1.0.30"

Expand Down
18 changes: 14 additions & 4 deletions dxr/src/values/ser_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(crate) mod base64 {
/// `<value><string>foo</string></value>` (which are both valid XML-RPC).
pub(crate) mod value {
use serde::{
de::{self, Deserializer, Visitor},
de::{self, Deserializer, IgnoredAny, Visitor},
Deserialize,
};
use std::fmt;
Expand Down Expand Up @@ -129,6 +129,7 @@ pub(crate) mod value {
"nil",
];

#[derive(Debug)]
enum Field {
I4,
#[cfg(feature = "i8")]
Expand Down Expand Up @@ -187,7 +188,7 @@ pub(crate) mod value {
}
}

if let Some(key) = map.next_key()? {
let value = if let Some(key) = map.next_key::<Field>()? {
match key {
Field::I4 => {
let value = map.next_value()?;
Expand Down Expand Up @@ -233,11 +234,20 @@ pub(crate) mod value {
Ok(Value::array(value))
},
#[cfg(feature = "nil")]
Field::Nil => Ok(Value::nil()),
Field::Nil => {
let _: IgnoredAny = map.next_value()?;
Ok(Value::nil())
},
}
} else {
// <value></value>
Ok(Value::string(String::new()))
return Ok(Value::string(String::new()));
};

if let Some(key) = map.next_key::<Field>()? {
Copy link

@Mingun Mingun Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably changing Field to have Unknown(Cow<str>) variant will be better to handle error more gracefully here. Then the error could be more clear that you have unexpected key even if that is not a key that Field can recognize. Currently for the field abcdef you will get "unknown field" error instead of "Unexpected key" error, but I think, that this key in the first place is unexpected and only after that is unknown.

With that variant emit unknown field error in match at line 191.

Also, it maybe worth to add some formal tests for the deserializer implementation using serde_test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into this, thank you!

Err(de::Error::custom(format!("Unexpected key: {:?}", key)))
} else {
value
}
}
}
Expand Down
Loading