diff --git a/Changelog.md b/Changelog.md index e16465a5..0e667010 100644 --- a/Changelog.md +++ b/Changelog.md @@ -18,6 +18,14 @@ In particular, that means that maps with numeric and numeric-like keys (for example, `"42"`) no longer can be serialized because [XML name] cannot start from a digit +- [#500]: Fix deserialization of top-level sequences of enums, like + ```xml + + + + + + ``` ### Misc Changes @@ -44,6 +52,7 @@ Refer to [documentation] for details. [#490]: https://github.com/tafia/quick-xml/pull/490 +[#500]: https://github.com/tafia/quick-xml/issues/500 [XML name]: https://www.w3.org/TR/xml11/#NT-Name [documentation]: https://docs.rs/quick-xml/0.27.0/quick_xml/de/index.html#difference-between-text-and-value-special-names diff --git a/src/de/seq.rs b/src/de/seq.rs index 00ad240e..6fc0fa72 100644 --- a/src/de/seq.rs +++ b/src/de/seq.rs @@ -74,20 +74,6 @@ where { /// Deserializer used to deserialize sequence items de: &'a mut Deserializer<'de, R>, - /// Filter that determines whether a tag is a part of this sequence. - /// - /// When feature `overlapped-lists` is not activated, iteration will stop - /// when found a tag that does not pass this filter. - /// - /// When feature `overlapped-lists` is activated, all tags, that not pass - /// this check, will be skipped. - filter: TagFilter<'de>, - - /// Checkpoint after which all skipped events should be returned. All events, - /// that was skipped before creating this checkpoint, will still stay buffered - /// and will not be returned - #[cfg(feature = "overlapped-lists")] - checkpoint: usize, } impl<'a, 'de, R> TopLevelSeqAccess<'de, 'a, R> @@ -96,29 +82,7 @@ where { /// Creates a new accessor to a top-level sequence of XML elements. pub fn new(de: &'a mut Deserializer<'de, R>) -> Result { - let filter = if let DeEvent::Start(e) = de.peek()? { - // Clone is cheap if event borrows from the input - TagFilter::Include(e.clone()) - } else { - TagFilter::Exclude(&[]) - }; - Ok(Self { - #[cfg(feature = "overlapped-lists")] - checkpoint: de.skip_checkpoint(), - - de, - filter, - }) - } -} - -#[cfg(feature = "overlapped-lists")] -impl<'de, 'a, R> Drop for TopLevelSeqAccess<'de, 'a, R> -where - R: XmlRead<'de>, -{ - fn drop(&mut self) { - self.de.start_replay(self.checkpoint); + Ok(Self { de }) } } @@ -132,24 +96,11 @@ where where T: DeserializeSeed<'de>, { - let decoder = self.de.reader.decoder(); - loop { - break match self.de.peek()? { - // If we see a tag that we not interested, skip it - #[cfg(feature = "overlapped-lists")] - DeEvent::Start(e) if !self.filter.is_suitable(e, decoder)? => { - self.de.skip()?; - continue; - } - // Stop iteration when list elements ends - #[cfg(not(feature = "overlapped-lists"))] - DeEvent::Start(e) if !self.filter.is_suitable(e, decoder)? => Ok(None), - DeEvent::End(_) => Ok(None), - DeEvent::Eof => Ok(None), + match self.de.peek()? { + DeEvent::Eof => Ok(None), - // Start(tag), Text, CData - _ => seed.deserialize(&mut *self.de).map(Some), - }; + // Start(tag), End(tag), Text, CData + _ => seed.deserialize(&mut *self.de).map(Some), } } } diff --git a/tests/serde-de.rs b/tests/serde-de.rs index 25994ec7..7ec1426c 100644 --- a/tests/serde-de.rs +++ b/tests/serde-de.rs @@ -609,6 +609,26 @@ mod seq { ] ); } + + /// Test for https://github.com/tafia/quick-xml/issues/500 + #[test] + fn list_of_enum() { + #[derive(Debug, PartialEq, Deserialize)] + enum Enum { + One, + Two, + } + + let data: Vec = from_str( + r#" + + + + "#, + ) + .unwrap(); + assert_eq!(data, vec![Enum::One, Enum::Two, Enum::One]); + } } /// Tests where each sequence item have an identical name in an XML.