Skip to content

Commit

Permalink
Merge pull request tafia#689 from Mingun/pos-in-error
Browse files Browse the repository at this point in the history
Fix `buffer_position()` after resuming parsing after `IllFormed` errors
  • Loading branch information
Mingun committed Dec 1, 2023
2 parents c383849 + f295b01 commit 222532c
Show file tree
Hide file tree
Showing 8 changed files with 692 additions and 538 deletions.
10 changes: 9 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ The way to configure parser is changed. Now all configuration is contained in th
`Config` struct and can be applied at once. When `serde-types` feature is enabled,
configuration is serializable.

The method of reporting positions of errors has changed - use `error_position()`
to get an offset of the error position. For `SyntaxError`s the range
`error_position()..buffer_position()` also will represent a span of error.

### New Features

- [#513]: Allow to continue parsing after getting new `Error::IllFormed`.
Expand Down Expand Up @@ -46,18 +50,22 @@ configuration is serializable.
- `Error::XmlDeclWithoutVersion` replaced by `IllFormedError::MissingDeclVersion` (in [#684])
- `Error::EmptyDocType` replaced by `IllFormedError::MissingDoctypeName` (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.
to the start of markup (i. e. to the `<` character) with error. Use `error_position()`
for that.
- [#684]: Now `<??>` parsed as `Event::PI` with empty content instead of raising
syntax error.
- [#684]: Now `<?xml?>` parsed as `Event::Decl` instead of `Event::PI`.
- [#362]: Now default quote level is `QuoteLevel::Partial` when using serde serializer.
- [#689]: `buffer_position()` now always report the position the parser last seen.
To get an error position use `error_position()`.

[#362]: https://github.com/tafia/quick-xml/issues/362
[#513]: https://github.com/tafia/quick-xml/issues/513
[#622]: https://github.com/tafia/quick-xml/issues/622
[#675]: https://github.com/tafia/quick-xml/pull/675
[#677]: https://github.com/tafia/quick-xml/pull/677
[#684]: https://github.com/tafia/quick-xml/pull/684
[#689]: https://github.com/tafia/quick-xml/pull/689


## 0.31.0 -- 2023-10-22
Expand Down
12 changes: 3 additions & 9 deletions src/reader/buffered_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ macro_rules! impl_buffered_source {
buf.push(b'!');
self $(.$reader)? .consume(1);

let bang_type = BangType::new(self.peek_one() $(.$await)? ?, position)?;
let bang_type = BangType::new(self.peek_one() $(.$await)? ?)?;

loop {
match self $(.$reader)? .fill_buf() $(.$await)? {
Expand Down Expand Up @@ -139,10 +139,7 @@ macro_rules! impl_buffered_source {
}
}

// <!....EOF
// ^^^^^ - `buf` does not contains `<`, but we want to report error at `<`,
// so we move offset to it (+1 for `<`)
*position -= 1;
*position += read;
Err(bang_type.to_err())
}

Expand Down Expand Up @@ -186,10 +183,7 @@ macro_rules! impl_buffered_source {
};
}

// <.....EOF
// ^^^^^ - `buf` does not contains `<`, but we want to report error at `<`,
// so we move offset to it (+1 for `<`)
*position -= 1;
*position += read;
Err(Error::Syntax(SyntaxError::UnclosedTag))
}

Expand Down

0 comments on commit 222532c

Please sign in to comment.