Skip to content

Commit 2e50e5c

Browse files
committed
Parse <??> as syntactically valid processing instruction
Although empty target name isnot allowed, we would check that (or change parsing) the same way as currently we check the presence of mandatory `version` attribute in XML declaration. This requires introducing separate type for PI content which will be done in tafia#650 Fixed (3): syntax::pi::normal_empty::async_tokio syntax::pi::normal_empty::borrowed syntax::pi::normal_empty::buffered failures (3): syntax::decl::normal1::async_tokio syntax::decl::normal1::borrowed syntax::decl::normal1::buffered
1 parent 6e4636b commit 2e50e5c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ configuration is serializable.
4242
- `Error::EmptyDocType` replaced by `IllFormedError::MissedDoctypeName` (in [#684])
4343
- [#684]: Changed positions reported for `SyntaxError`s: now they are always points
4444
to the start of markup (i. e. to the `<` character) with error.
45+
- [#684]: Now `<??>` parsed as `Event::PI` with empty content instead of raising
46+
syntax error.
4547

4648
[#513]: https://github.com/tafia/quick-xml/issues/513
4749
[#622]: https://github.com/tafia/quick-xml/issues/622

src/reader/state.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,13 @@ impl ReaderState {
190190
///
191191
/// Returns `Decl` or `PI` event
192192
pub fn emit_question_mark<'b>(&mut self, buf: &'b [u8]) -> Result<Event<'b>> {
193+
debug_assert!(buf.len() > 0);
194+
debug_assert_eq!(buf[0], b'?');
195+
193196
let len = buf.len();
194-
if len > 2 && buf[len - 1] == b'?' {
197+
// We accept at least <??>
198+
// ~~ - len = 2
199+
if len > 1 && buf[len - 1] == b'?' {
195200
if len > 5 && &buf[1..4] == b"xml" && is_whitespace(buf[4]) {
196201
let event = BytesDecl::from_start(BytesStart::wrap(&buf[1..len - 1], 3));
197202

0 commit comments

Comments
 (0)