Skip to content

Commit

Permalink
Deprecate unnecessary unescaping of tags
Browse files Browse the repository at this point in the history
Fixes  tafia#341
  • Loading branch information
kornelski committed Jun 19, 2022
1 parent e701c4d commit 35dfdca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ impl<'a> BytesStart<'a> {
/// "`<`".
///
/// See also [`unescaped_with_custom_entities()`](#method.unescaped_with_custom_entities)
#[inline]
#[cold]
#[deprecated(note = "Tag names are never escaped. Attributes must be unescaped individually")]
#[allow(deprecated)]
#[doc(hidden)]
pub fn unescaped(&self) -> Result<Cow<[u8]>> {
self.make_unescaped(None)
}
Expand All @@ -195,15 +198,19 @@ impl<'a> BytesStart<'a> {
/// The keys and values of `custom_entities`, if any, must be valid UTF-8.
///
/// See also [`unescaped()`](#method.unescaped)
#[inline]
#[cold]
#[deprecated(note = "Tag names are never escaped. Attributes must be unescaped individually")]
#[allow(deprecated)]
#[doc(hidden)]
pub fn unescaped_with_custom_entities<'s>(
&'s self,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>,
) -> Result<Cow<'s, [u8]>> {
self.make_unescaped(Some(custom_entities))
}

#[inline]
#[cold]
#[deprecated(note = "Tag names are never escaped. Attributes must be unescaped individually")]
fn make_unescaped<'s>(
&'s self,
custom_entities: Option<&HashMap<Vec<u8>, Vec<u8>>>,
Expand All @@ -221,7 +228,10 @@ impl<'a> BytesStart<'a> {
///
/// [`unescaped()`]: #method.unescaped
/// [`Reader::decode()`]: ../reader/struct.Reader.html#method.decode
#[inline]
#[cold]
#[deprecated(note = "Tag names are never escaped. Attributes must be unescaped individually")]
#[allow(deprecated)]
#[doc(hidden)]
pub fn unescape_and_decode<B: BufRead>(&self, reader: &Reader<B>) -> Result<String> {
self.do_unescape_and_decode_with_custom_entities(reader, None)
}
Expand All @@ -240,7 +250,10 @@ impl<'a> BytesStart<'a> {
/// # Pre-condition
///
/// The keys and values of `custom_entities`, if any, must be valid UTF-8.
#[inline]
#[cold]
#[deprecated(note = "Tag names are never escaped. Attributes must be unescaped individually")]
#[allow(deprecated)]
#[doc(hidden)]
pub fn unescape_and_decode_with_custom_entities<B: BufRead>(
&self,
reader: &Reader<B>,
Expand All @@ -250,7 +263,10 @@ impl<'a> BytesStart<'a> {
}

#[cfg(feature = "encoding")]
#[inline]
#[cold]
#[deprecated(note = "Tag names are never escaped. Attributes must be unescaped individually")]
#[allow(deprecated)]
#[doc(hidden)]
fn do_unescape_and_decode_with_custom_entities<B: BufRead>(
&self,
reader: &Reader<B>,
Expand All @@ -263,7 +279,10 @@ impl<'a> BytesStart<'a> {
}

#[cfg(not(feature = "encoding"))]
#[inline]
#[cold]
#[deprecated(note = "Tag names are never escaped. Attributes must be unescaped individually")]
#[allow(deprecated)]
#[doc(hidden)]
fn do_unescape_and_decode_with_custom_entities<B: BufRead>(
&self,
reader: &Reader<B>,
Expand Down
1 change: 1 addition & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ fn fuzz_101() {
loop {
match reader.read_event(&mut buf) {
Ok(Start(ref e)) | Ok(Empty(ref e)) => {
#[allow(deprecated)]
if e.unescaped().is_err() {
break;
}
Expand Down

0 comments on commit 35dfdca

Please sign in to comment.