diff --git a/Changelog.md b/Changelog.md index f1bf2801..7935c3f9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -22,9 +22,13 @@ instruction between a 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 diff --git a/src/reader/ns_reader.rs b/src/reader/ns_reader.rs index 4f8cb23a..1470d14c 100644 --- a/src/reader/ns_reader.rs +++ b/src/reader/ns_reader.rs @@ -524,7 +524,11 @@ impl NsReader { pub fn read_to_end_into(&mut self, end: QName, buf: &mut Vec) -> Result { // 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) } } @@ -760,7 +764,11 @@ impl<'i> NsReader<&'i [u8]> { pub fn read_to_end(&mut self, end: QName) -> Result { // 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 @@ -830,7 +838,13 @@ impl<'i> NsReader<&'i [u8]> { /// [`decoder()`]: Reader::decoder() #[inline] pub fn read_text(&mut self, end: QName) -> Result> { - 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) } }