Skip to content

Commit

Permalink
Trim Text events after DOCTYPE so spaces does not produce an event.
Browse files Browse the repository at this point in the history
Otherwise consequent `Text` events (which is possible if their delimited by
Comment or PI events, which is skipped) will be merged but not trimmed.
That will lead to returning a `Text` event when try to call `deserialize_struct`
or `deserialize_map` which will trigger `DeError::ExpectedStart` error.

The incorrect trim behavior was introduced in #581, when DocType event began to be processed
  • Loading branch information
Dan Griffin authored and Mingun committed Jun 9, 2023
1 parent c8332d9 commit d49f2d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@

### Bug Fixes

- [#603]: Fix a regression from [#581] that an XML comment or a processing
instruction between a <!DOCTYPE> and the root element in the file brokes
deserialization of structs by returning `DeError::ExpectedStart`

### Misc Changes

[#581]: https://github.com/tafia/quick-xml/pull/581
[#601]: https://github.com/tafia/quick-xml/pull/601
[#603]: https://github.com/tafia/quick-xml/pull/603
[#606]: https://github.com/tafia/quick-xml/pull/606


Expand Down
2 changes: 1 addition & 1 deletion src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2880,7 +2880,7 @@ impl StartTrimmer {
#[inline(always)]
fn trim<'a>(&mut self, event: Event<'a>) -> Option<PayloadEvent<'a>> {
let (event, trim_next_event) = match event {
Event::DocType(e) => (PayloadEvent::DocType(e), false),
Event::DocType(e) => (PayloadEvent::DocType(e), true),
Event::Start(e) => (PayloadEvent::Start(e), true),
Event::End(e) => (PayloadEvent::End(e), true),
Event::Eof => (PayloadEvent::Eof, true),
Expand Down

0 comments on commit d49f2d5

Please sign in to comment.