mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-30 13:19:02 +00:00
LibWeb: Ensure document.getElementsByClassName("")
returns no elements
Previously, `document.getElementsByClassName("")` would return a collection containing all elements in the given document.
This commit is contained in:
parent
faf64bfb41
commit
0fceede029
Notes:
github-actions[bot]
2024-07-23 06:59:20 +00:00
Author: https://github.com/tcl3
Commit: 0fceede029
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/773
4 changed files with 23 additions and 10 deletions
|
@ -0,0 +1 @@
|
||||||
|
document.getElementsByClassName("").length: 0
|
|
@ -0,0 +1,8 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<div class=""></div>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
println(`document.getElementsByClassName("").length: ${document.getElementsByClassName("").length}`);
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -471,6 +471,9 @@ void Element::attribute_changed(FlyString const& name, Optional<String> const&,
|
||||||
|
|
||||||
document().element_name_changed({}, *this);
|
document().element_name_changed({}, *this);
|
||||||
} else if (name == HTML::AttributeNames::class_) {
|
} else if (name == HTML::AttributeNames::class_) {
|
||||||
|
if (value_or_empty.is_empty()) {
|
||||||
|
m_classes.clear();
|
||||||
|
} else {
|
||||||
auto new_classes = value_or_empty.bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace);
|
auto new_classes = value_or_empty.bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace);
|
||||||
m_classes.clear();
|
m_classes.clear();
|
||||||
m_classes.ensure_capacity(new_classes.size());
|
m_classes.ensure_capacity(new_classes.size());
|
||||||
|
@ -479,6 +482,7 @@ void Element::attribute_changed(FlyString const& name, Optional<String> const&,
|
||||||
}
|
}
|
||||||
if (m_class_list)
|
if (m_class_list)
|
||||||
m_class_list->associated_attribute_changed(value_or_empty);
|
m_class_list->associated_attribute_changed(value_or_empty);
|
||||||
|
}
|
||||||
} else if (name == HTML::AttributeNames::style) {
|
} else if (name == HTML::AttributeNames::style) {
|
||||||
if (!value.has_value()) {
|
if (!value.has_value()) {
|
||||||
if (m_inline_style) {
|
if (m_inline_style) {
|
||||||
|
|
|
@ -234,10 +234,10 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_class_name(StringVi
|
||||||
}
|
}
|
||||||
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) {
|
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) {
|
||||||
for (auto& name : list_of_class_names) {
|
for (auto& name : list_of_class_names) {
|
||||||
if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
if (element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue