Skip to content

Commit c9ad25b

Browse files
Mingundralley
andcommitted
Use separate offset for errors
In the perfect world we would add offset to the `Error` type, but right now this is impractical, because this significantly changes some API that would be removed soon Co-authored-by: Daniel Alley <[email protected]>
1 parent 0c2936c commit c9ad25b

File tree

6 files changed

+133
-126
lines changed

6 files changed

+133
-126
lines changed

Changelog.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ The way to configure parser is changed. Now all configuration is contained in th
1414
`Config` struct and can be applied at once. When `serde-types` feature is enabled,
1515
configuration is serializable.
1616

17+
The method of reporting positions of errors has changed - use `error_position()`
18+
to get an offset of the error position. For `SyntaxError`s the range
19+
`error_position()..buffer_position()` also will represent a span of error.
20+
1721
### New Features
1822

1923
- [#513]: Allow to continue parsing after getting new `Error::IllFormed`.
@@ -46,18 +50,22 @@ configuration is serializable.
4650
- `Error::XmlDeclWithoutVersion` replaced by `IllFormedError::MissingDeclVersion` (in [#684])
4751
- `Error::EmptyDocType` replaced by `IllFormedError::MissingDoctypeName` (in [#684])
4852
- [#684]: Changed positions reported for `SyntaxError`s: now they are always points
49-
to the start of markup (i. e. to the `<` character) with error.
53+
to the start of markup (i. e. to the `<` character) with error. Use `error_position()`
54+
for that.
5055
- [#684]: Now `<??>` parsed as `Event::PI` with empty content instead of raising
5156
syntax error.
5257
- [#684]: Now `<?xml?>` parsed as `Event::Decl` instead of `Event::PI`.
5358
- [#362]: Now default quote level is `QuoteLevel::Partial` when using serde serializer.
59+
- [#689]: `buffer_position()` now always report the position the parser last seen.
60+
To get an error position use `error_position()`.
5461

5562
[#362]: https://github.com/tafia/quick-xml/issues/362
5663
[#513]: https://github.com/tafia/quick-xml/issues/513
5764
[#622]: https://github.com/tafia/quick-xml/issues/622
5865
[#675]: https://github.com/tafia/quick-xml/pull/675
5966
[#677]: https://github.com/tafia/quick-xml/pull/677
6067
[#684]: https://github.com/tafia/quick-xml/pull/684
68+
[#689]: https://github.com/tafia/quick-xml/pull/689
6169

6270

6371
## 0.31.0 -- 2023-10-22

src/reader/buffered_reader.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ macro_rules! impl_buffered_source {
105105
buf.push(b'!');
106106
self $(.$reader)? .consume(1);
107107

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

110110
loop {
111111
match self $(.$reader)? .fill_buf() $(.$await)? {
@@ -139,10 +139,7 @@ macro_rules! impl_buffered_source {
139139
}
140140
}
141141

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

@@ -186,10 +183,7 @@ macro_rules! impl_buffered_source {
186183
};
187184
}
188185

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

0 commit comments

Comments
 (0)