Skip to content

Commit 9921bfb

Browse files
Mingundralley
authored andcommitted
Actually check that content is borrowed when it is not changed
1 parent add7406 commit 9921bfb

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/escapei.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,13 @@ fn parse_decimal(bytes: &str) -> Result<u32, EscapeError> {
17411741

17421742
#[test]
17431743
fn test_unescape() {
1744-
assert_eq!(unescape("test").unwrap(), Cow::Borrowed("test"));
1744+
let unchanged = unescape("test").unwrap();
1745+
// assert_eq does not check that Cow is borrowed, but we explicitly use Cow
1746+
// because it influences diff
1747+
// TODO: use assert_matches! when stabilized and other features will bump MSRV
1748+
assert_eq!(unchanged, Cow::Borrowed("test"));
1749+
assert!(matches!(unchanged, Cow::Borrowed(_)));
1750+
17451751
assert_eq!(unescape("&lt;test&gt;").unwrap(), "<test>");
17461752
assert_eq!(unescape("&#x30;").unwrap(), "0");
17471753
assert_eq!(unescape("&#48;").unwrap(), "0");
@@ -1755,10 +1761,13 @@ fn test_unescape_with() {
17551761
_ => None,
17561762
};
17571763

1758-
assert_eq!(
1759-
unescape_with("test", custom_entities).unwrap(),
1760-
Cow::Borrowed("test")
1761-
);
1764+
let unchanged = unescape_with("test", custom_entities).unwrap();
1765+
// assert_eq does not check that Cow is borrowed, but we explicitly use Cow
1766+
// because it influences diff
1767+
// TODO: use assert_matches! when stabilized and other features will bump MSRV
1768+
assert_eq!(unchanged, Cow::Borrowed("test"));
1769+
assert!(matches!(unchanged, Cow::Borrowed(_)));
1770+
17621771
assert_eq!(
17631772
unescape_with("&lt;test&gt;", custom_entities).unwrap(),
17641773
"<test>"
@@ -1771,7 +1780,13 @@ fn test_unescape_with() {
17711780

17721781
#[test]
17731782
fn test_escape() {
1774-
assert_eq!(escape("test"), Cow::Borrowed("test"));
1783+
let unchanged = escape("test");
1784+
// assert_eq does not check that Cow is borrowed, but we explicitly use Cow
1785+
// because it influences diff
1786+
// TODO: use assert_matches! when stabilized and other features will bump MSRV
1787+
assert_eq!(unchanged, Cow::Borrowed("test"));
1788+
assert!(matches!(unchanged, Cow::Borrowed(_)));
1789+
17751790
assert_eq!(escape("<test>"), "&lt;test&gt;");
17761791
assert_eq!(escape("\"a\"bc"), "&quot;a&quot;bc");
17771792
assert_eq!(escape("\"a\"b&c"), "&quot;a&quot;b&amp;c");
@@ -1783,7 +1798,13 @@ fn test_escape() {
17831798

17841799
#[test]
17851800
fn test_partial_escape() {
1786-
assert_eq!(partial_escape("test"), Cow::Borrowed("test"));
1801+
let unchanged = partial_escape("test");
1802+
// assert_eq does not check that Cow is borrowed, but we explicitly use Cow
1803+
// because it influences diff
1804+
// TODO: use assert_matches! when stabilized and other features will bump MSRV
1805+
assert_eq!(unchanged, Cow::Borrowed("test"));
1806+
assert!(matches!(unchanged, Cow::Borrowed(_)));
1807+
17871808
assert_eq!(partial_escape("<test>"), "&lt;test&gt;");
17881809
assert_eq!(partial_escape("\"a\"bc"), "\"a\"bc");
17891810
assert_eq!(partial_escape("\"a\"b&c"), "\"a\"b&amp;c");

src/reader/slice_reader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl<'a> Reader<&'a [u8]> {
212212
/// <p>Usual XML rules does not apply inside it
213213
/// <p>For example, elements not needed to be &quot;closed&quot;
214214
/// "#));
215+
/// assert!(matches!(text, Cow::Borrowed(_)));
215216
///
216217
/// // Now we can enable checks again
217218
/// reader.check_end_names(true);

0 commit comments

Comments
 (0)