diff --git a/src/de/key.rs b/src/de/key.rs index 0c003730..8cd6c6ba 100644 --- a/src/de/key.rs +++ b/src/de/key.rs @@ -41,7 +41,7 @@ fn decode_name<'n>(name: QName<'n>, decoder: Decoder) -> Result, 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: @@ -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(); diff --git a/tests/serde-issues.rs b/tests/serde-issues.rs index 2726e45a..7af06298 100644 --- a/tests/serde-issues.rs +++ b/tests/serde-issues.rs @@ -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::(r#""#) + .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#""# + ); + } +}