mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +00:00
LibWeb: Clarify attribute selectors when needle is empty
This commit is contained in:
parent
8f3326616a
commit
049d847230
1 changed files with 19 additions and 6 deletions
|
@ -84,17 +84,30 @@ static inline bool matches_attribute(CSS::Selector::SimpleSelector::Attribute co
|
||||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::ExactValueMatch:
|
case CSS::Selector::SimpleSelector::Attribute::MatchType::ExactValueMatch:
|
||||||
return element.attribute(attribute.name) == attribute.value;
|
return element.attribute(attribute.name) == attribute.value;
|
||||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsWord:
|
case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsWord:
|
||||||
return element.attribute(attribute.name).split_view(' ').contains_slow(attribute.value);
|
return !attribute.value.is_empty()
|
||||||
|
&& element.attribute(attribute.name).split_view(' ').contains_slow(attribute.value);
|
||||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsString:
|
case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsString:
|
||||||
return element.attribute(attribute.name).contains(attribute.value);
|
return !attribute.value.is_empty()
|
||||||
|
&& element.attribute(attribute.name).contains(attribute.value);
|
||||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithSegment: {
|
case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithSegment: {
|
||||||
auto segments = element.attribute(attribute.name).split_view('-');
|
const auto element_attr_value = element.attribute(attribute.name);
|
||||||
return !segments.is_empty() && segments.first() == attribute.value;
|
if (element_attr_value.is_empty()) {
|
||||||
|
// If the attribute value on element is empty, the selector is true
|
||||||
|
// if the match value is also empty and false otherwise.
|
||||||
|
return attribute.value.is_empty();
|
||||||
|
}
|
||||||
|
if (attribute.value.is_empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto segments = element_attr_value.split_view('-');
|
||||||
|
return segments.first() == attribute.value;
|
||||||
}
|
}
|
||||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithString:
|
case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithString:
|
||||||
return element.attribute(attribute.name).starts_with(attribute.value);
|
return !attribute.value.is_empty()
|
||||||
|
&& element.attribute(attribute.name).starts_with(attribute.value);
|
||||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::EndsWithString:
|
case CSS::Selector::SimpleSelector::Attribute::MatchType::EndsWithString:
|
||||||
return element.attribute(attribute.name).ends_with(attribute.value);
|
return !attribute.value.is_empty()
|
||||||
|
&& element.attribute(attribute.name).ends_with(attribute.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue