diff options
author | HampusM <hampus@hampusmat.com> | 2023-02-26 22:00:53 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-02-26 22:00:53 +0100 |
commit | 49b9b754ffee693045ce3650be9eb21f7fae22cc (patch) | |
tree | 7f30e96df052b04cc07cf59310ae0a0001d0039e | |
parent | fbaf9c0e7357e9701a072963c59359e35a021a57 (diff) |
fix: unescape XML text
-rw-r--r-- | src/xml/parser.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/xml/parser.rs b/src/xml/parser.rs index 9cdafb1..bc8240c 100644 --- a/src/xml/parser.rs +++ b/src/xml/parser.rs @@ -1,5 +1,6 @@ use std::io::BufRead; +use quick_xml::escape::unescape; use quick_xml::events::attributes::AttrError; use quick_xml::events::{BytesStart, BytesText, Event}; use quick_xml::Reader; @@ -48,7 +49,13 @@ impl<Source: BufRead> Parser<Source> fn parse_text(text: &BytesText) -> Result<String, Error> { - String::from_utf8(text.to_vec()).map_err(|_| Error::TextNotUTF8) + let text_escaped = + String::from_utf8(text.to_vec()).map_err(|_| Error::TextNotUTF8)?; + + let text_unescaped = unescape(&text_escaped) + .map_err(|err| Error::QuickXMLFailed(quick_xml::Error::EscapeError(err)))?; + + Ok(text_unescaped.to_string()) } fn parse_tagged(&mut self, start: &BytesStart) -> Result<Element, Error> |