Skip to content

Commit

Permalink
Minor tweak after quick-xml upgrade
Browse files Browse the repository at this point in the history
- map unknown namespaces to default (else we just fail when trying
  to parse them)
- move the unescape/decode inside the check so we avoid doing it when
  the text is empty
  • Loading branch information
markpritchard committed Sep 27, 2022
1 parent 5f4e55f commit b385509
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions feed-rs/src/xml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,7 @@ impl<R: BufRead> SourceState<R> {
.decode(ns.as_ref())
.map(|decoded| NS::parse(decoded.as_ref()))
.unwrap_or(self.default_namespace),
ResolveResult::Unknown(bytes) => decoder
.decode(&bytes)
.map(|decoded| NS::parse(decoded.as_ref()))
.unwrap_or(self.default_namespace),
ResolveResult::Unknown(_) => self.default_namespace,
ResolveResult::Unbound => self.default_namespace,
};

Expand Down Expand Up @@ -540,12 +537,12 @@ impl XmlEvent {

// Creates a new event corresponding to an XML text node
fn text<R: BufRead>(text: &BytesText, reader: &Reader<R>) -> XmlResult<Option<XmlEvent>> {
let escaped_text = reader.decoder().decode(text)?;
let unescaped_text = escape::unescape(&escaped_text).map_err(quick_xml::Error::EscapeError)?;

if text.is_empty() {
Ok(None)
} else {
let escaped_text = reader.decoder().decode(text)?;
let unescaped_text = escape::unescape(&escaped_text).map_err(quick_xml::Error::EscapeError)?;

Ok(Some(XmlEvent::Text(unescaped_text.to_string())))
}
}
Expand Down

0 comments on commit b385509

Please sign in to comment.