mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-10-26 06:49:12 +03: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: https://github.com/LadybirdBrowser/ladybird/commit/0fceede029e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/773
@ -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,14 +471,18 @@ void Element::attribute_changed(FlyString const& name, Optional<String> const&,
|
||||
|
||||
document().element_name_changed({}, *this);
|
||||
} else if (name == HTML::AttributeNames::class_) {
|
||||
auto new_classes = value_or_empty.bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace);
|
||||
m_classes.clear();
|
||||
m_classes.ensure_capacity(new_classes.size());
|
||||
for (auto& new_class : new_classes) {
|
||||
m_classes.unchecked_append(FlyString::from_utf8(new_class).release_value_but_fixme_should_propagate_errors());
|
||||
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);
|
||||
m_classes.clear();
|
||||
m_classes.ensure_capacity(new_classes.size());
|
||||
for (auto& new_class : new_classes) {
|
||||
m_classes.unchecked_append(FlyString::from_utf8(new_class).release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
if (m_class_list)
|
||||
m_class_list->associated_attribute_changed(value_or_empty);
|
||||
}
|
||||
if (m_class_list)
|
||||
m_class_list->associated_attribute_changed(value_or_empty);
|
||||
} else if (name == HTML::AttributeNames::style) {
|
||||
if (!value.has_value()) {
|
||||
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) {
|
||||
for (auto& name : list_of_class_names) {
|
||||
if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
||||
return false;
|
||||
if (element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user