Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@

### Bug Fixes

- [#939]: Fix parsing error of the tag from buffered reader, when the first byte `<`
is the last in the `BufRead` internal buffer. This is the regression from [#936].


### Misc Changes

[#936]: https://github.com/tafia/quick-xml/pull/936
[#939]: https://github.com/tafia/quick-xml/issues/939


## 0.39.1 -- 2026-02-15

Expand Down
1 change: 1 addition & 0 deletions src/reader/async_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ mod test {
read_event_into_async,
read_until_close_async,
TokioAdapter,
1,
&mut Vec::new(),
async,
await
Expand Down
18 changes: 10 additions & 8 deletions src/reader/buffered_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ macro_rules! impl_buffered_source {
buf: &'b mut Vec<u8>,
position: &mut u64,
) -> Result<&'b [u8]> {
let mut read = 0;
let mut read = 1;
let start = buf.len();
// '<' was consumed in peek_one(), but not placed in buf
buf.push(b'<');
loop {
let available = match self $(.$reader)? .fill_buf() $(.$await)? {
Ok(n) if n.is_empty() => break,
Expand Down Expand Up @@ -240,9 +242,10 @@ macro_rules! impl_buffered_source {
// Peeked '<!' before being called, so it's guaranteed to start with it.
let start = buf.len();
let mut read = 2;
// '<' was consumed in peek_one(), but not placed in buf
buf.push(b'<');
buf.push(b'!');
self $(.$reader)? .consume(2);
self $(.$reader)? .consume(1);

let mut bang_type = loop {
break match self $(.$reader)? .fill_buf() $(.$await)? {
Expand Down Expand Up @@ -310,19 +313,17 @@ macro_rules! impl_buffered_source {

#[inline]
$($async)? fn peek_one(&mut self) -> io::Result<Option<u8>> {
// That method is called only when available buffer starts from '<'
// We need to consume it
self $(.$reader)? .consume(1);
let available = loop {
break match self $(.$reader)? .fill_buf() $(.$await)? {
Ok(n) => n,
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) => return Err(e),
};
};
debug_assert!(
available.starts_with(b"<"),
"markup must start from '<':\n{:?}",
crate::utils::Bytes(available)
);
Ok(available.get(1).cloned())
Ok(available.first().cloned())
}
};
}
Expand Down Expand Up @@ -512,6 +513,7 @@ mod test {
read_event_impl,
read_until_close,
identity,
1,
&mut Vec::new()
);
}
Loading