Skip to content

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 (1):
    trivial::struct_::cdata::byte_buf
  • Loading branch information
Mingun committed May 3, 2022
1 parent eb8c523 commit 52b18f0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -32,6 +32,7 @@
- fix: fix internal panic message when parse malformed XML
([#344](https://github.com/tafia/quick-xml/issues/344))
- 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
Expand Up @@ -109,7 +109,7 @@ where
} 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
Expand Up @@ -597,7 +597,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
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 52b18f0

Please sign in to comment.