Skip to content

Commit

Permalink
Fix DOCTYPE closing tag recognition in bufread
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueGreenMagick committed Sep 19, 2024
1 parent 2f3824a commit 9fafd50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,10 +1088,13 @@ impl BangType {
Self::DocType => {
for i in memchr::memchr_iter(b'>', chunk) {
let content = &chunk[..i];
let balance = memchr::memchr2_iter(b'<', b'>', content)
let balance_buf = memchr::memchr2_iter(b'<', b'>', buf)
.map(|p| if buf[p] == b'<' { 1i32 } else { -1 })
.sum::<i32>();
let balance_content = memchr::memchr2_iter(b'<', b'>', content)
.map(|p| if content[p] == b'<' { 1i32 } else { -1 })
.sum::<i32>();
if balance == 0 {
if balance_buf + balance_content == 0 {
return Some((content, i + 1)); // +1 for `>`
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,19 @@ fn issue776() {
Event::End(BytesEnd::new(r#"tag attr=">""#))
);
}

/// Regression test for https://github.com/tafia/quick-xml/issues/801
#[test]
fn issue801() {
let xml = BufReader::with_capacity(4, b"<!DOCTYPE X [<!-- --><!ENTITY a \"a\">]>" as &[u8]);
let mut reader = Reader::from_reader(xml);
let mut buf = Vec::new();
loop {
buf.clear();
match reader.read_event_into(&mut buf) {
Err(e) => panic!("Error at position {}: {:?}", reader.error_position(), e),
Ok(Event::Eof) => {break}
Ok(_) => {}
}
}
}

0 comments on commit 9fafd50

Please sign in to comment.