diff --git a/src/events/mod.rs b/src/events/mod.rs index eb6516ef..c0b9a924 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -885,7 +885,7 @@ pub enum Event<'a> { Decl(BytesDecl<'a>), /// Processing instruction ``. PI(BytesText<'a>), - /// Doctype ``. + /// Doctype ``. DocType(BytesText<'a>), /// End of XML document. Eof, diff --git a/src/reader.rs b/src/reader.rs index 961c9be2..cf050133 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -371,7 +371,12 @@ impl Reader { Ok(Event::CData(BytesText::from_plain(&buf[8..buf.len() - 2]))) } else if uncased_starts_with(buf, b"!DOCTYPE") { debug_assert!(len >= 8, "Minimum length guaranteed by read_bang_elem"); - Ok(Event::DocType(BytesText::from_escaped(&buf[8..]))) + let start = buf[8..] + .iter() + .position(|b| !is_whitespace(*b)) + .unwrap_or_else(|| buf.len() - 8); + debug_assert!(start < buf.len() - 8, "DocType must have a name"); + Ok(Event::DocType(BytesText::from_escaped(&buf[8 + start..]))) } else { unreachable!("Proper bang start guaranteed by read_bang_elem"); } diff --git a/src/writer.rs b/src/writer.rs index 04ed699d..73a7dc2e 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -119,7 +119,7 @@ impl Writer { } Event::Decl(ref e) => self.write_wrapped(b""), Event::PI(ref e) => self.write_wrapped(b""), - Event::DocType(ref e) => self.write_wrapped(b""), + Event::DocType(ref e) => self.write_wrapped(b""), Event::Eof => Ok(()), }; if let Some(i) = self.indent.as_mut() { diff --git a/tests/documents/html5.txt b/tests/documents/html5.txt index 1ad39c09..f1bc908b 100644 --- a/tests/documents/html5.txt +++ b/tests/documents/html5.txt @@ -1,4 +1,4 @@ -DocType( html) +DocType(html) Characters( ) StartElement(a, attr-error: error while parsing attribute at position 7: Attribute value must start with a quote.) diff --git a/tests/documents/sample_4_full.txt b/tests/documents/sample_4_full.txt index 4bdadfb7..82ef6ef3 100644 --- a/tests/documents/sample_4_full.txt +++ b/tests/documents/sample_4_full.txt @@ -1,4 +1,5 @@ StartDocument(1.0, utf-8) +DocType(data SYSTEM "abcd.dtd") StartElement({urn:x}p:data [z=">"]) Whitespace("\n ") Comment(" abcd < > & ") diff --git a/tests/documents/sample_4_short.txt b/tests/documents/sample_4_short.txt index 33035902..7262b033 100644 --- a/tests/documents/sample_4_short.txt +++ b/tests/documents/sample_4_short.txt @@ -1,15 +1,16 @@ StartDocument(1.0, utf-8) -DocType(DOCTYPE data SYSTEM "abcd.dtd") +DocType(data SYSTEM "abcd.dtd") StartElement({urn:x}p:data [z=">"]) +Comment( abcd < > & ) StartElement(a) -Characters("test") +Characters(test) EndElement(a) StartElement(b) -Characters("kkss\" = ddd\' >") +Characters(kkss" = ddd' >) EndElement(b) -Characters("ddddd!e3-->