Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes in unescape routine #771

Merged
merged 10 commits into from
Jun 29, 2024
Prev Previous commit
Next Next commit
Reuse existing method with does the same thing when encoding featur…
…e is disabled
Mingun committed Jun 28, 2024
commit aa1d391e206fa9630e22241082b89a4e693f1ccd
14 changes: 2 additions & 12 deletions src/events/attributes.rs
Original file line number Diff line number Diff line change
@@ -63,22 +63,12 @@ impl<'a> Attribute<'a> {
///
/// [`encoding`]: ../../index.html#encoding
#[cfg(any(doc, not(feature = "encoding")))]
#[inline]
pub fn unescape_value_with<'entity>(
&self,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> XmlResult<Cow<'a, str>> {
// from_utf8 should never fail because content is always UTF-8 encoded
let decoded = match &self.value {
Cow::Borrowed(bytes) => Cow::Borrowed(std::str::from_utf8(bytes)?),
// Convert to owned, because otherwise Cow will be bound with wrong lifetime
Cow::Owned(bytes) => Cow::Owned(std::str::from_utf8(bytes)?.to_string()),
};

match unescape_with(&decoded, resolve_entity)? {
// Because result is borrowed, no replacements was done and we can use original string
Cow::Borrowed(_) => Ok(decoded),
Cow::Owned(s) => Ok(s.into()),
}
self.decode_and_unescape_value_with(Decoder::utf8(), resolve_entity)
}

/// Decodes then unescapes the value.