Skip to content

Commit 30fe118

Browse files
Merge pull request #9 from GuillaumeGomez/fix-attrs
Fix attrs
2 parents dade0f1 + a287e96 commit 30fe118

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "html-diff"
3-
version = "0.0.3"
3+
version = "0.0.4"
44
authors = ["Guillaume Gomez <[email protected]>"]
55

66
description = "Library detect HTML diffs"

src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn check_elements(elem1: &NodeDataRef<ElementData>,
188188
elem: ElementInformation::new(elem1, path),
189189
opposite_elem: ElementInformation::new(elem2, path),
190190
})
191-
} else if (*e1.attributes.borrow()).map.len() != (*e2.attributes.borrow()).map.len() {
191+
} else {
192192
let all_attributes_match =
193193
(*e1.attributes.borrow()).map.iter().any(|(k, v)| {
194194
(*e2.attributes.borrow()).map.get(k) != Some(v)
@@ -217,8 +217,6 @@ fn check_elements(elem1: &NodeDataRef<ElementData>,
217217
} else {
218218
None
219219
}
220-
} else {
221-
None
222220
}
223221
}
224222

@@ -429,3 +427,16 @@ fn test_issue_6() {
429427
let b = "<mark></mark><div class=\"paragraph\"><p>chunky bacon</p></div><mark></mark>";
430428
let _ = get_differences(a, b);
431429
}
430+
431+
#[test]
432+
fn test_attributes() {
433+
let a = r#"<span class="toto"></span>"#;
434+
let b = r#"<span class="tata"></span>"#;
435+
let differences = get_differences(a, b);
436+
assert_eq!(differences.len(), 1);
437+
438+
let a = r#"<span foo="a" class="toto"></span>"#;
439+
let b = r#"<span class="toto" foo="a"></span>"#;
440+
let differences = get_differences(a, b);
441+
assert_eq!(differences.len(), 0);
442+
}

0 commit comments

Comments
 (0)