Skip to content

Commit d49f2d5

Browse files
Dan GriffinMingun
Dan Griffin
authored andcommitted
Trim Text events after DOCTYPE so spaces does not produce an event.
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 tafia#581, when DocType event began to be processed
1 parent c8332d9 commit d49f2d5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818

1919
### Bug Fixes
2020

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

27+
[#581]: https://github.com/tafia/quick-xml/pull/581
2328
[#601]: https://github.com/tafia/quick-xml/pull/601
29+
[#603]: https://github.com/tafia/quick-xml/pull/603
2430
[#606]: https://github.com/tafia/quick-xml/pull/606
2531

2632

src/de/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2880,7 +2880,7 @@ impl StartTrimmer {
28802880
#[inline(always)]
28812881
fn trim<'a>(&mut self, event: Event<'a>) -> Option<PayloadEvent<'a>> {
28822882
let (event, trim_next_event) = match event {
2883-
Event::DocType(e) => (PayloadEvent::DocType(e), false),
2883+
Event::DocType(e) => (PayloadEvent::DocType(e), true),
28842884
Event::Start(e) => (PayloadEvent::Start(e), true),
28852885
Event::End(e) => (PayloadEvent::End(e), true),
28862886
Event::Eof => (PayloadEvent::Eof, true),

0 commit comments

Comments
 (0)