diff --git a/Changelog.md b/Changelog.md index 9729e010..361d06b2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -30,12 +30,15 @@ ### Bug Fixes - [#806]: Properly normalize EOL characters in `Deserializer`. +- [#888]: Properly split attribute values by items when deserialize attribute into + list of values and attribute requires decoding. ### Misc Changes [#806]: https://github.com/tafia/quick-xml/issues/806 [#878]: https://github.com/tafia/quick-xml/pull/878 [#882]: https://github.com/tafia/quick-xml/pull/882 +[#888]: https://github.com/tafia/quick-xml/pull/888 ## 0.38.0 -- 2025-06-28 diff --git a/src/de/simple_type.rs b/src/de/simple_type.rs index a3810663..41db1273 100644 --- a/src/de/simple_type.rs +++ b/src/de/simple_type.rs @@ -430,7 +430,8 @@ impl<'de, 'a> SeqAccess<'de> for ListIter<'de, 'a> { // Skip additional bytes if we own data for next iteration, but deserialize from // the borrowed data from our buffer Content::Owned(s, skip) => { - let item = s.split_at(skip + end).0; + let rest = s.split_at(skip).1; + let item = rest.split_at(end).0; let result = seed.deserialize(AtomicDeserializer { content: CowRef::Slice(item), escaped: self.escaped, diff --git a/tests/serde-issues.rs b/tests/serde-issues.rs index 14c44688..6e06f55b 100644 --- a/tests/serde-issues.rs +++ b/tests/serde-issues.rs @@ -674,3 +674,38 @@ fn issue868() { ), } } + +/// Regression test for https://github.com/tafia/quick-xml/pull/888. +#[cfg(feature = "encoding")] +#[test] +fn issue888() { + #[derive(Debug, PartialEq, Deserialize)] + struct Root { + #[serde(rename = "@list")] + list: Vec, + } + + let xml = r#" + + "#; + + let (xml, enc, _) = dbg!(encoding_rs::WINDOWS_1251.encode(xml)); + assert_eq!( + enc, + encoding_rs::WINDOWS_1251, + "windows-1251 should be used for the test" + ); + + let data: Root = quick_xml::de::from_reader(xml.as_ref()).unwrap(); + assert_eq!( + data, + Root { + list: vec![ + // Translation from Russian: + "текст".to_string(), // text + "требующий".to_string(), // that-requires + "декодирования".to_string(), // decoding + ], + } + ); +}