Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Handle CDATA events in the deserializer - this fixes almost all CDATA…
Browse files Browse the repository at this point in the history
… trivial tests

failures:
    de::tests::trivial::struct_::text::byte_buf
    de::tests::trivial::struct_::cdata::byte_buf
  • Loading branch information
Mingun committed Mar 20, 2022
1 parent 128f93a commit fd04e5f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- fix: allow to deserialize `unit`s from text and CDATA content.
`DeError::InvalidUnit` variant is removed, because after fix it is no longer used
- test: add tests for trivial documents (empty / only comment / `<root>...</root>` -- one tag with content)
- fix: CDATA was not handled in many cases where it should

## 0.23.0-alpha3

Expand Down
2 changes: 1 addition & 1 deletion src/de/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'de, 'a, R: BorrowingReader<'de>> de::MapAccess<'de> for MapAccess<'de, 'a,
} else {
// try getting from events (<key>value</key>)
match self.de.peek()? {
DeEvent::Text(_) => {
DeEvent::Text(_) | DeEvent::CData(_) => {
self.state = State::InnerValue;
// Deserialize `key` from special attribute name which means
// that value should be taken from the text content of the
Expand Down
2 changes: 1 addition & 1 deletion src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ where
V: Visitor<'de>,
{
match self.peek()? {
DeEvent::Text(t) if t.is_empty() => visitor.visit_none(),
DeEvent::Text(t) | DeEvent::CData(t) if t.is_empty() => visitor.visit_none(),
DeEvent::Eof => visitor.visit_none(),
_ => visitor.visit_some(self),
}
Expand Down
4 changes: 3 additions & 1 deletion src/de/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ where
let decoder = self.de.reader.decoder();
let de = match self.de.peek()? {
DeEvent::Text(t) => EscapedDeserializer::new(Cow::Borrowed(t), decoder, true),
// Escape sequences does not processed inside CDATA section
DeEvent::CData(t) => EscapedDeserializer::new(Cow::Borrowed(t), decoder, false),
DeEvent::Start(e) => EscapedDeserializer::new(Cow::Borrowed(e.name()), decoder, false),
_ => {
return Err(DeError::Unsupported(
Expand Down Expand Up @@ -64,7 +66,7 @@ where
fn unit_variant(self) -> Result<(), DeError> {
match self.de.next()? {
DeEvent::Start(e) => self.de.read_to_end(e.name()),
DeEvent::Text(_) => Ok(()),
DeEvent::Text(_) | DeEvent::CData(_) => Ok(()),
_ => unreachable!(),
}
}
Expand Down

0 comments on commit fd04e5f

Please sign in to comment.