Skip to content

Commit

Permalink
Update Changelog/test for comment after DOCTYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Griffin committed Jun 8, 2023
1 parent 1ad03aa commit 9a0664d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

### Bug Fixes

- [#603]: Make it possible to include an XML comment between a <!DOCTYPE> and
the root element in the file.

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

### Misc Changes

[#601]: https://github.com/tafia/quick-xml/pull/601
Expand Down
22 changes: 22 additions & 0 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2880,6 +2880,8 @@ impl StartTrimmer {
#[inline(always)]
fn trim<'a>(&mut self, event: Event<'a>) -> Option<PayloadEvent<'a>> {
let (event, trim_next_event) = match event {
// Trim CData/Text events after DOCTYPE so next event encountered
// by deserializer will be a Start event (allowing Struct parser to suceed)
Event::DocType(e) => (PayloadEvent::DocType(e), true),
Event::Start(e) => (PayloadEvent::Start(e), true),
Event::End(e) => (PayloadEvent::End(e), true),
Expand Down Expand Up @@ -4450,4 +4452,24 @@ mod tests {
}
}
}

#[test]
fn allow_comments_between_doctype_and_root_element() {
let mut de = Deserializer::from_str(r#"
<!DOCTYPE dict>
<!-- comment between doctype and root element -->
<!-- another comment -->
<doc>
</doc>
"#);
assert_eq!(
de.next().unwrap(),
DeEvent::Start(BytesStart::new("doc"))
);
assert_eq!(
de.next().unwrap(),
DeEvent::End(BytesEnd::new("doc"))
);
assert_eq!(de.next().unwrap(), DeEvent::Eof);
}
}

0 comments on commit 9a0664d

Please sign in to comment.