Skip to content

Commit c214c51

Browse files
authored
Merge pull request #888 from Mingun/fix-attr-list-de
Fix attribute splitting into items when deserialize into list and decode is required
2 parents 6a6d23c + b312a23 commit c214c51

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@
3030
### Bug Fixes
3131

3232
- [#806]: Properly normalize EOL characters in `Deserializer`.
33+
- [#888]: Properly split attribute values by items when deserialize attribute into
34+
list of values and attribute requires decoding.
3335

3436
### Misc Changes
3537

3638
[#806]: https://github.com/tafia/quick-xml/issues/806
3739
[#878]: https://github.com/tafia/quick-xml/pull/878
3840
[#882]: https://github.com/tafia/quick-xml/pull/882
41+
[#888]: https://github.com/tafia/quick-xml/pull/888
3942

4043

4144
## 0.38.0 -- 2025-06-28

src/de/simple_type.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ impl<'de, 'a> SeqAccess<'de> for ListIter<'de, 'a> {
430430
// Skip additional bytes if we own data for next iteration, but deserialize from
431431
// the borrowed data from our buffer
432432
Content::Owned(s, skip) => {
433-
let item = s.split_at(skip + end).0;
433+
let rest = s.split_at(skip).1;
434+
let item = rest.split_at(end).0;
434435
let result = seed.deserialize(AtomicDeserializer {
435436
content: CowRef::Slice(item),
436437
escaped: self.escaped,

tests/serde-issues.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,3 +674,38 @@ fn issue868() {
674674
),
675675
}
676676
}
677+
678+
/// Regression test for https://github.com/tafia/quick-xml/pull/888.
679+
#[cfg(feature = "encoding")]
680+
#[test]
681+
fn issue888() {
682+
#[derive(Debug, PartialEq, Deserialize)]
683+
struct Root {
684+
#[serde(rename = "@list")]
685+
list: Vec<String>,
686+
}
687+
688+
let xml = r#"
689+
<?xml version="1.0" encoding="windows-1251"?>
690+
<root list="текст требующий декодирования"/>"#;
691+
692+
let (xml, enc, _) = dbg!(encoding_rs::WINDOWS_1251.encode(xml));
693+
assert_eq!(
694+
enc,
695+
encoding_rs::WINDOWS_1251,
696+
"windows-1251 should be used for the test"
697+
);
698+
699+
let data: Root = quick_xml::de::from_reader(xml.as_ref()).unwrap();
700+
assert_eq!(
701+
data,
702+
Root {
703+
list: vec![
704+
// Translation from Russian:
705+
"текст".to_string(), // text
706+
"требующий".to_string(), // that-requires
707+
"декодирования".to_string(), // decoding
708+
],
709+
}
710+
);
711+
}

0 commit comments

Comments
 (0)