Skip to content

Commit

Permalink
Fix tafia#597: Pop namespace scope after NsReader::read_to_end[_into]…
Browse files Browse the repository at this point in the history
… and read_text
  • Loading branch information
Mingun committed Jun 10, 2023
1 parent d546deb commit 4fa1f92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
instruction between a <!DOCTYPE> and the root element in the file brokes
deserialization of structs by returning `DeError::ExpectedStart`

- [#597]: Fixed incorrect processing of namespace scopes in `NsReader::read_to_end`.
The scope started by a start element was not ended after that call.

### Misc Changes

[#581]: https://github.com/tafia/quick-xml/pull/581
[#597]: https://github.com/tafia/quick-xml/issues/597
[#601]: https://github.com/tafia/quick-xml/pull/601
[#603]: https://github.com/tafia/quick-xml/pull/603
[#606]: https://github.com/tafia/quick-xml/pull/606
Expand Down
20 changes: 17 additions & 3 deletions src/reader/ns_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,11 @@ impl<R: BufRead> NsReader<R> {
pub fn read_to_end_into(&mut self, end: QName, buf: &mut Vec<u8>) -> Result<Span> {
// According to the https://www.w3.org/TR/xml11/#dt-etag, end name should
// match literally the start name. See `Self::check_end_names` documentation
self.reader.read_to_end_into(end, buf)
let result = self.reader.read_to_end_into(end, buf)?;
// read_to_end_into will consume closing tag. Because nobody can access to its
// content anymore, we directly pop namespace of the opening tag
self.ns_resolver.pop(&mut self.buffer);
Ok(result)
}
}

Expand Down Expand Up @@ -760,7 +764,11 @@ impl<'i> NsReader<&'i [u8]> {
pub fn read_to_end(&mut self, end: QName) -> Result<Span> {
// According to the https://www.w3.org/TR/xml11/#dt-etag, end name should
// match literally the start name. See `Self::check_end_names` documentation
self.reader.read_to_end(end)
let result = self.reader.read_to_end(end)?;
// read_to_end will consume closing tag. Because nobody can access to its
// content anymore, we directly pop namespace of the opening tag
self.ns_resolver.pop(&mut self.buffer);
Ok(result)
}

/// Reads content between start and end tags, including any markup. This
Expand Down Expand Up @@ -830,7 +838,13 @@ impl<'i> NsReader<&'i [u8]> {
/// [`decoder()`]: Reader::decoder()
#[inline]
pub fn read_text(&mut self, end: QName) -> Result<Cow<'i, str>> {
self.reader.read_text(end)
// According to the https://www.w3.org/TR/xml11/#dt-etag, end name should
// match literally the start name. See `Self::check_end_names` documentation
let result = self.reader.read_text(end)?;
// read_text will consume closing tag. Because nobody can access to its
// content anymore, we directly pop namespace of the opening tag
self.ns_resolver.pop(&mut self.buffer);
Ok(result)
}
}

Expand Down

0 comments on commit 4fa1f92

Please sign in to comment.