Skip to content

Commit 4fa1f92

Browse files
committed
Fix tafia#597: Pop namespace scope after NsReader::read_to_end[_into] and read_text
1 parent d546deb commit 4fa1f92

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
instruction between a <!DOCTYPE> and the root element in the file brokes
2323
deserialization of structs by returning `DeError::ExpectedStart`
2424

25+
- [#597]: Fixed incorrect processing of namespace scopes in `NsReader::read_to_end`.
26+
The scope started by a start element was not ended after that call.
27+
2528
### Misc Changes
2629

2730
[#581]: https://github.com/tafia/quick-xml/pull/581
31+
[#597]: https://github.com/tafia/quick-xml/issues/597
2832
[#601]: https://github.com/tafia/quick-xml/pull/601
2933
[#603]: https://github.com/tafia/quick-xml/pull/603
3034
[#606]: https://github.com/tafia/quick-xml/pull/606

src/reader/ns_reader.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,11 @@ impl<R: BufRead> NsReader<R> {
524524
pub fn read_to_end_into(&mut self, end: QName, buf: &mut Vec<u8>) -> Result<Span> {
525525
// According to the https://www.w3.org/TR/xml11/#dt-etag, end name should
526526
// match literally the start name. See `Self::check_end_names` documentation
527-
self.reader.read_to_end_into(end, buf)
527+
let result = self.reader.read_to_end_into(end, buf)?;
528+
// read_to_end_into will consume closing tag. Because nobody can access to its
529+
// content anymore, we directly pop namespace of the opening tag
530+
self.ns_resolver.pop(&mut self.buffer);
531+
Ok(result)
528532
}
529533
}
530534

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

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

0 commit comments

Comments
 (0)