Skip to content

Commit

Permalink
Parse <??> as syntactically valid processing instruction
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mingun committed Nov 21, 2023
1 parent 486da77 commit d6648b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ configuration is serializable.
- `Error::EmptyDocType` replaced by `IllFormedError::MissedDoctypeName` (in [#684])
- [#684]: Changed positions reported for `SyntaxError`s: now they are always points
to the start of markup (i. e. to the `<` character) with error.
- [#684]: Now `<??>` parsed as `Event::PI` with empty content instead of raising
syntax error.

[#513]: https://github.com/tafia/quick-xml/issues/513
[#622]: https://github.com/tafia/quick-xml/issues/622
Expand Down
7 changes: 6 additions & 1 deletion src/reader/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,13 @@ impl ReaderState {
///
/// Returns `Decl` or `PI` event
pub fn emit_question_mark<'b>(&mut self, buf: &'b [u8]) -> Result<Event<'b>> {
debug_assert!(buf.len() > 0);
debug_assert_eq!(buf[0], b'?');

let len = buf.len();
if len > 2 && buf[len - 1] == b'?' {
// We accept at least <??>
// ~~ - len = 2
if len > 1 && buf[len - 1] == b'?' {
if len > 5 && &buf[1..4] == b"xml" && is_whitespace(buf[4]) {
let event = BytesDecl::from_start(BytesStart::wrap(&buf[1..len - 1], 3));

Expand Down

0 comments on commit d6648b2

Please sign in to comment.