mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Fix checking for empty set for getElementsByClassName
Because empty set with `.all(predicate)` will always return `true`, it will result in always filtering wrong elements when the classes is empty set. Thus, we return earlier with `always_empty` HTMLCollection in the mpety classes case so that we can avoid filtering on empty sets.
This commit is contained in:
parent
9acb9cc5cf
commit
c77e4e4e69
2 changed files with 6 additions and 10 deletions
|
@ -252,11 +252,17 @@ impl HTMLCollection {
|
|||
let case_sensitivity = document_from_node(elem)
|
||||
.quirks_mode()
|
||||
.classes_and_ids_case_sensitivity();
|
||||
|
||||
self.classes
|
||||
.iter()
|
||||
.all(|class| elem.has_class(class, case_sensitivity))
|
||||
}
|
||||
}
|
||||
|
||||
if classes.is_empty() {
|
||||
return HTMLCollection::always_empty(window, root);
|
||||
}
|
||||
|
||||
let filter = ClassNameFilter { classes: classes };
|
||||
HTMLCollection::create(window, root, Box::new(filter))
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
[getElementsByClassName-empty-set.html]
|
||||
[Passing a space to getElementsByClassName should return an empty HTMLCollection]
|
||||
expected: FAIL
|
||||
|
||||
[Passing three spaces to getElementsByClassName should return an empty HTMLCollection]
|
||||
expected: FAIL
|
||||
|
||||
[Passing an empty string to getElementsByClassName should return an empty HTMLCollection]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue