mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 13:35:12 +00:00
LibWeb: Use correct case-sensitivity when matching attribute selectors
Also removed get_attribute_with_lowercase_qualified_name because it was buggy, duplicated logic, and now unused.
This commit is contained in:
parent
a2cf1d17fd
commit
ba0cc7fe46
Notes:
github-actions[bot]
2024-11-23 08:51:33 +00:00
Author: https://github.com/Gingeh Commit: https://github.com/LadybirdBrowser/ladybird/commit/ba0cc7fe461 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2478 Reviewed-by: https://github.com/AtkinsSJ
4 changed files with 12 additions and 29 deletions
|
@ -219,8 +219,7 @@ static inline bool matches_attribute(CSS::Selector::SimpleSelector::Attribute co
|
|||
|
||||
auto const& attribute_name = attribute.qualified_name.name.name;
|
||||
|
||||
auto const* attr = element.namespace_uri() == Namespace::HTML ? element.attributes()->get_attribute_with_lowercase_qualified_name(attribute_name)
|
||||
: element.attributes()->get_attribute(attribute_name);
|
||||
auto const* attr = element.attributes()->get_attribute(attribute_name);
|
||||
|
||||
if (attribute.match_type == CSS::Selector::SimpleSelector::Attribute::MatchType::HasAttribute) {
|
||||
// Early way out in case of an attribute existence selector.
|
||||
|
|
|
@ -148,8 +148,7 @@ Attr const* NamedNodeMap::get_attribute(FlyString const& qualified_name, size_t*
|
|||
*item_index = 0;
|
||||
|
||||
// 1. If element is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in ASCII lowercase.
|
||||
// FIXME: Handle the second condition, assume it is an HTML document for now.
|
||||
bool compare_as_lowercase = associated_element().namespace_uri() == Namespace::HTML;
|
||||
bool compare_as_lowercase = associated_element().namespace_uri() == Namespace::HTML && associated_element().document().is_html_document();
|
||||
|
||||
// 2. Return the first attribute in element’s attribute list whose qualified name is qualifiedName; otherwise null.
|
||||
for (auto const& attribute : m_attributes) {
|
||||
|
@ -168,19 +167,6 @@ Attr const* NamedNodeMap::get_attribute(FlyString const& qualified_name, size_t*
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Attr const* NamedNodeMap::get_attribute_with_lowercase_qualified_name(FlyString const& lowercase_qualified_name) const
|
||||
{
|
||||
bool compare_as_lowercase = associated_element().namespace_uri() == Namespace::HTML;
|
||||
VERIFY(compare_as_lowercase);
|
||||
|
||||
for (auto const& attribute : m_attributes) {
|
||||
if (attribute->lowercase_name() == lowercase_qualified_name)
|
||||
return attribute;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-namespace
|
||||
Attr* NamedNodeMap::get_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& local_name, size_t* item_index)
|
||||
{
|
||||
|
|
|
@ -53,8 +53,6 @@ public:
|
|||
Attr const* remove_attribute(FlyString const& qualified_name);
|
||||
Attr const* remove_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& local_name);
|
||||
|
||||
Attr const* get_attribute_with_lowercase_qualified_name(FlyString const&) const;
|
||||
|
||||
WebIDL::ExceptionOr<GC::Ref<Attr>> remove_attribute_node(GC::Ref<Attr>);
|
||||
|
||||
private:
|
||||
|
|
|
@ -6,8 +6,8 @@ Rerun
|
|||
|
||||
Found 1975 tests
|
||||
|
||||
1923 Pass
|
||||
52 Fail
|
||||
1931 Pass
|
||||
44 Fail
|
||||
Details
|
||||
Result Test Name MessagePass Selectors-API Test Suite: HTML
|
||||
Pass Document supports querySelector
|
||||
|
@ -414,8 +414,8 @@ Pass Document.querySelectorAll: Attribute presence selector, matching align attr
|
|||
Pass Document.querySelector: Attribute presence selector, matching align attribute with value: .attr-presence-div1[align]
|
||||
Pass Document.querySelectorAll: Attribute presence selector, matching align attribute with empty value: .attr-presence-div2[align]
|
||||
Pass Document.querySelector: Attribute presence selector, matching align attribute with empty value: .attr-presence-div2[align]
|
||||
Fail Document.querySelectorAll: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Fail Document.querySelector: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass Document.querySelectorAll: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass Document.querySelector: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass Document.querySelectorAll: Attribute presence selector, matching custom data-* attribute: [data-attr-presence]
|
||||
Pass Document.querySelector: Attribute presence selector, matching custom data-* attribute: [data-attr-presence]
|
||||
Pass Document.querySelectorAll: Attribute presence selector, not matching attribute with similar name: .attr-presence-div3[align], .attr-presence-div4[align]
|
||||
|
@ -810,8 +810,8 @@ Pass Detached Element.querySelectorAll: Attribute presence selector, matching al
|
|||
Pass Detached Element.querySelector: Attribute presence selector, matching align attribute with value: .attr-presence-div1[align]
|
||||
Pass Detached Element.querySelectorAll: Attribute presence selector, matching align attribute with empty value: .attr-presence-div2[align]
|
||||
Pass Detached Element.querySelector: Attribute presence selector, matching align attribute with empty value: .attr-presence-div2[align]
|
||||
Fail Detached Element.querySelectorAll: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Fail Detached Element.querySelector: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass Detached Element.querySelectorAll: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass Detached Element.querySelector: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass Detached Element.querySelectorAll: Attribute presence selector, matching custom data-* attribute: [data-attr-presence]
|
||||
Pass Detached Element.querySelector: Attribute presence selector, matching custom data-* attribute: [data-attr-presence]
|
||||
Pass Detached Element.querySelectorAll: Attribute presence selector, not matching attribute with similar name: .attr-presence-div3[align], .attr-presence-div4[align]
|
||||
|
@ -1206,8 +1206,8 @@ Pass Fragment.querySelectorAll: Attribute presence selector, matching align attr
|
|||
Pass Fragment.querySelector: Attribute presence selector, matching align attribute with value: .attr-presence-div1[align]
|
||||
Pass Fragment.querySelectorAll: Attribute presence selector, matching align attribute with empty value: .attr-presence-div2[align]
|
||||
Pass Fragment.querySelector: Attribute presence selector, matching align attribute with empty value: .attr-presence-div2[align]
|
||||
Fail Fragment.querySelectorAll: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Fail Fragment.querySelector: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass Fragment.querySelectorAll: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass Fragment.querySelector: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass Fragment.querySelectorAll: Attribute presence selector, matching custom data-* attribute: [data-attr-presence]
|
||||
Pass Fragment.querySelector: Attribute presence selector, matching custom data-* attribute: [data-attr-presence]
|
||||
Pass Fragment.querySelectorAll: Attribute presence selector, not matching attribute with similar name: .attr-presence-div3[align], .attr-presence-div4[align]
|
||||
|
@ -1602,8 +1602,8 @@ Pass In-document Element.querySelectorAll: Attribute presence selector, matching
|
|||
Pass In-document Element.querySelector: Attribute presence selector, matching align attribute with value: .attr-presence-div1[align]
|
||||
Pass In-document Element.querySelectorAll: Attribute presence selector, matching align attribute with empty value: .attr-presence-div2[align]
|
||||
Pass In-document Element.querySelector: Attribute presence selector, matching align attribute with empty value: .attr-presence-div2[align]
|
||||
Fail In-document Element.querySelectorAll: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Fail In-document Element.querySelector: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass In-document Element.querySelectorAll: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass In-document Element.querySelector: Attribute presence selector, matching title attribute, case insensitivity: #attr-presence [*|TiTlE]
|
||||
Pass In-document Element.querySelectorAll: Attribute presence selector, matching custom data-* attribute: [data-attr-presence]
|
||||
Pass In-document Element.querySelector: Attribute presence selector, matching custom data-* attribute: [data-attr-presence]
|
||||
Pass In-document Element.querySelectorAll: Attribute presence selector, not matching attribute with similar name: .attr-presence-div3[align], .attr-presence-div4[align]
|
||||
|
|
Loading…
Add table
Reference in a new issue