From e62e870ef0e220fc59316a095a07a41c833e67bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 7 Dec 2019 17:39:49 +0100 Subject: [PATCH] minidom: strictly compare whitespace in Element's PartialEq impl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- minidom-rs/src/element.rs | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/minidom-rs/src/element.rs b/minidom-rs/src/element.rs index 9d04065..fd27d9b 100644 --- a/minidom-rs/src/element.rs +++ b/minidom-rs/src/element.rs @@ -99,21 +99,9 @@ impl PartialEq for Element { fn eq(&self, other: &Self) -> bool { if self.name() == other.name() && self.ns() == other.ns() && self.attrs().eq(other.attrs()) { - let child_elems = self.children().count(); - let text_is_whitespace = self - .texts() - .all(|text| text.chars().all(char::is_whitespace)); - if child_elems > 0 && text_is_whitespace { - // Ignore all the whitespace text nodes - self.children() - .zip(other.children()) - .all(|(node1, node2)| node1 == node2) - } else { - // Compare with text nodes - self.nodes() - .zip(other.nodes()) - .all(|(node1, node2)| node1 == node2) - } + self.nodes() + .zip(other.nodes()) + .all(|(node1, node2)| node1 == node2) } else { false } @@ -1076,4 +1064,25 @@ mod tests { let elem = Element::from_reader(&mut reader).unwrap(); assert_eq!(elem.text(), "'>blah"); } + + #[test] + fn test_compare_all_ns() { + let xml = ""; + let mut reader = EventReader::from_str(xml); + let elem = Element::from_reader(&mut reader).unwrap(); + + let elem2 = elem.clone(); + + let xml3 = ""; + let mut reader3 = EventReader::from_str(xml3); + let elem3 = Element::from_reader(&mut reader3).unwrap(); + + let xml4 = ""; + let mut reader4 = EventReader::from_str(xml4); + let elem4 = Element::from_reader(&mut reader4).unwrap(); + + assert_eq!(elem, elem2); + assert_eq!(elem, elem3); + assert_eq!(elem, elem4); + } }