Skip to content

Commit 4a1ab95

Browse files
authored
Merge pull request #32 from farodin91/fixes-issue-3
Prevent infinite loop at the end of the document
2 parents 3848ff9 + 5b93e6f commit 4a1ab95

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/de/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ impl<'de, R: Read> Deserializer<R> {
104104
loop {
105105
match self.reader.next().map_err(ErrorKind::Syntax)? {
106106
XmlEvent::StartDocument { .. } |
107-
XmlEvent::EndDocument { .. } |
108107
XmlEvent::ProcessingInstruction { .. } |
109108
XmlEvent::Comment(_) => { /* skip */ },
110-
111109
other => return Ok(other),
112110
}
113111
}

src/de/seq.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ impl<'de, 'a, R: 'a + Read> de::SeqAccess<'de> for SeqAccess<'a, R> {
4444
(&XmlEvent::StartElement { ref name, .. }, Some(expected_name)) => {
4545
&name.local_name == expected_name
4646
},
47-
(&XmlEvent::EndElement { .. }, None) | (_, Some(_)) => false,
47+
(&XmlEvent::EndElement { .. }, None) |
48+
(_, Some(_)) |
49+
(&XmlEvent::EndDocument { .. }, _) => false,
4850
(_, None) => true,
4951
};
5052
if more {

tests/migrated.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ fn test_parse_enum() {
256256
use self::Animal::*;
257257
init_logger();
258258

259-
init_logger();
260-
261259
test_parse_ok(&[
262260
("<Animal xsi:type=\"Dog\"/>", Dog),
263261
(

tests/test.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ fn simple_struct_from_attributes() {
2727
);
2828
}
2929

30+
#[test]
31+
fn multiple_roots_attributes() {
32+
let s = r##"
33+
<item name="hello" source="world.rs" />
34+
<item name="hello" source="world.rs" />
35+
"##;
36+
37+
let item: Vec<Item> = from_str(s).unwrap();
38+
39+
assert_eq!(
40+
item,
41+
vec![
42+
Item {
43+
name: "hello".to_string(),
44+
source: "world.rs".to_string(),
45+
},
46+
Item {
47+
name: "hello".to_string(),
48+
source: "world.rs".to_string(),
49+
},
50+
]
51+
);
52+
}
53+
3054
#[test]
3155
fn simple_struct_from_attribute_and_child() {
3256
let s = r##"

0 commit comments

Comments
 (0)