Skip to content

Commit 703f078

Browse files
committed
Remove BytesStart::unescaped* set of methods because they could return wrong results
Removed example actually did not show nothing useful and was wrong after all
1 parent 038bfed commit 703f078

File tree

4 files changed

+3
-235
lines changed

4 files changed

+3
-235
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
is returned regardless of the status of the feature.
9090
- [#180]: Error variant `Error::Utf8` replaced by `Error::NonDecodable`
9191

92+
- [#118]: Remove `BytesStart::unescaped*` set of methods because they could return wrong results
93+
Use methods on `Attribute` instead
94+
9295
### New Tests
9396

9497
- [#9]: Added tests for incorrect nested tags in input

examples/issue68.rs

Lines changed: 0 additions & 144 deletions
This file was deleted.

src/events/mod.rs

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -231,94 +231,6 @@ impl<'a> BytesStart<'a> {
231231
self.name().into()
232232
}
233233

234-
/// Gets the unescaped tag name.
235-
///
236-
/// XML escape sequences like "`&lt;`" will be replaced by their unescaped characters like
237-
/// "`<`".
238-
///
239-
/// See also [`unescaped_with_custom_entities()`](#method.unescaped_with_custom_entities)
240-
#[inline]
241-
pub fn unescaped(&self) -> Result<Cow<[u8]>> {
242-
self.make_unescaped(None)
243-
}
244-
245-
/// Gets the unescaped tag name, using custom entities.
246-
///
247-
/// XML escape sequences like "`&lt;`" will be replaced by their unescaped characters like
248-
/// "`<`".
249-
/// Additional entities can be provided in `custom_entities`.
250-
///
251-
/// # Pre-condition
252-
///
253-
/// The keys and values of `custom_entities`, if any, must be valid UTF-8.
254-
///
255-
/// See also [`unescaped()`](#method.unescaped)
256-
#[inline]
257-
pub fn unescaped_with_custom_entities<'s>(
258-
&'s self,
259-
custom_entities: &HashMap<Vec<u8>, Vec<u8>>,
260-
) -> Result<Cow<'s, [u8]>> {
261-
self.make_unescaped(Some(custom_entities))
262-
}
263-
264-
#[inline]
265-
fn make_unescaped<'s>(
266-
&'s self,
267-
custom_entities: Option<&HashMap<Vec<u8>, Vec<u8>>>,
268-
) -> Result<Cow<'s, [u8]>> {
269-
do_unescape(&*self.buf, custom_entities).map_err(Error::EscapeError)
270-
}
271-
272-
/// Returns the unescaped and decoded string value.
273-
///
274-
/// This allocates a `String` in all cases. For performance reasons it might be a better idea to
275-
/// instead use one of:
276-
///
277-
/// * [`unescaped()`], as it doesn't allocate when no escape sequences are used.
278-
/// * [`Reader::decode()`], as it only allocates when the decoding can't be performed otherwise.
279-
///
280-
/// [`unescaped()`]: #method.unescaped
281-
/// [`Reader::decode()`]: ../reader/struct.Reader.html#method.decode
282-
#[inline]
283-
pub fn unescape_and_decode<B: BufRead>(&self, reader: &Reader<B>) -> Result<String> {
284-
self.do_unescape_and_decode_with_custom_entities(reader, None)
285-
}
286-
287-
/// Returns the unescaped and decoded string value with custom entities.
288-
///
289-
/// This allocates a `String` in all cases. For performance reasons it might be a better idea to
290-
/// instead use one of:
291-
///
292-
/// * [`unescaped_with_custom_entities()`], as it doesn't allocate when no escape sequences are used.
293-
/// * [`Reader::decode()`], as it only allocates when the decoding can't be performed otherwise.
294-
///
295-
/// [`unescaped_with_custom_entities()`]: #method.unescaped_with_custom_entities
296-
/// [`Reader::decode()`]: ../reader/struct.Reader.html#method.decode
297-
///
298-
/// # Pre-condition
299-
///
300-
/// The keys and values of `custom_entities`, if any, must be valid UTF-8.
301-
#[inline]
302-
pub fn unescape_and_decode_with_custom_entities<B: BufRead>(
303-
&self,
304-
reader: &Reader<B>,
305-
custom_entities: &HashMap<Vec<u8>, Vec<u8>>,
306-
) -> Result<String> {
307-
self.do_unescape_and_decode_with_custom_entities(reader, Some(custom_entities))
308-
}
309-
310-
#[inline]
311-
fn do_unescape_and_decode_with_custom_entities<B: BufRead>(
312-
&self,
313-
reader: &Reader<B>,
314-
custom_entities: Option<&HashMap<Vec<u8>, Vec<u8>>>,
315-
) -> Result<String> {
316-
let decoded = reader.decoder().decode(&*self)?;
317-
318-
let unescaped = do_unescape(decoded.as_bytes(), custom_entities)?;
319-
Ok(String::from_utf8(unescaped.into_owned())?)
320-
}
321-
322234
/// Edit the name of the BytesStart in-place
323235
///
324236
/// # Warning

tests/test.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ fn fuzz_101() {
156156
loop {
157157
match reader.read_event(&mut buf) {
158158
Ok(Start(ref e)) | Ok(Empty(ref e)) => {
159-
if e.unescaped().is_err() {
160-
break;
161-
}
162159
for a in e.attributes() {
163160
if a.ok().map_or(true, |a| a.unescaped_value().is_err()) {
164161
break;

0 commit comments

Comments
 (0)