Skip to content

fix namespace prefix deserialize #797

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 4 additions & 2 deletions src/de/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn decode_name<'n>(name: QName<'n>, decoder: Decoder) -> Result<Cow<'n, str>, De
/// to the identifier
/// - put the decoded [`local_name()`] of a name to the identifier
///
/// The final identifier looks like `[@]local_name`, or `@xmlns`, or `@xmlns:binding`
/// The final identifier looks like `[@]local_name`, or `@xmlns`, or `@xmlns:binding`, or `@r:id`
/// (where `[]` means optional element).
///
/// The deserializer also supports deserializing names as other primitive types:
Expand Down Expand Up @@ -86,7 +86,9 @@ impl<'i, 'd> QNameDeserializer<'i, 'd> {

// https://github.com/tafia/quick-xml/issues/537
// Namespace bindings (xmlns:xxx) map to `@xmlns:xxx` instead of `@xxx`
if name.as_namespace_binding().is_some() {
// https://github.com/tafia/quick-xml/issues/591
// Or any namespace prefix (e.g. r:id) map to `@r:id` instead of `@id`
if name.as_namespace_binding().is_some() || name.prefix().is_some() {
decoder.decode_into(name.into_inner(), key_buf)?;
} else {
let local = name.local_name();
Expand Down
40 changes: 40 additions & 0 deletions tests/serde-issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,43 @@ fn issue683() {
}
);
}

/// Regression test for https://github.com/tafia/quick-xml/issues/591.
mod issue591 {
use super::*;
use pretty_assertions::assert_eq;

#[derive(Debug, PartialEq, Deserialize, Serialize)]
#[serde(rename = "p:sldLayoutId")]
struct CtSlideLayoutIdListEntry<'a> {
#[serde(rename = "@id")]
id_attr: &'a str,

#[serde(rename = "@r:id")]
r_id_attr: &'a str,
}

#[test]
fn de() {
assert_eq!(
from_str::<CtSlideLayoutIdListEntry>(r#"<p:sldLayoutId id="2147483649" r:id="rId1"/>"#)
.unwrap(),
CtSlideLayoutIdListEntry {
id_attr: "2147483649",
r_id_attr: "rId1",
}
);
}

#[test]
fn se() {
assert_eq!(
to_string(&CtSlideLayoutIdListEntry {
id_attr: "2147483649",
r_id_attr: "rId1",
})
.unwrap(),
r#"<p:sldLayoutId id="2147483649" r:id="rId1"/>"#
);
}
}