mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibWeb: Fix issues with CSS attribute selector handling
This is three small, related changes: 1. Element::has_attribute() now returns true if the attribute exists but has no value. (eg, `<div foo />` -> `has_attribute("foo")`) 2. SelectorEngine::matches_attribute() now makes sure there is a first segment before comparing it, fixing a crash. 3. CSS::Parser now converts attribute names in attribute selectors to lowercase, to match the expectations of the rest of the system. Converting to lowercase is not always correct, depending on language, but since we only currently support HTML, and that expects them to be case-insensitive, it is fine for now.
This commit is contained in:
parent
242c342fad
commit
1b72766e4e
3 changed files with 11 additions and 4 deletions
|
@ -416,7 +416,12 @@ Result<Selector::SimpleSelector, Parser::SelectorParsingResult> Parser::parse_si
|
|||
.type = Selector::SimpleSelector::Type::Attribute,
|
||||
.attribute = {
|
||||
.match_type = Selector::SimpleSelector::Attribute::MatchType::HasAttribute,
|
||||
.name = attribute_part.token().ident(),
|
||||
// FIXME: Case-sensitivity is defined by the document language.
|
||||
// HTML is insensitive with attribute names, and our code generally assumes
|
||||
// they are converted to lowercase, so we do that here too. If we want to be
|
||||
// correct with XML later, we'll need to keep the original case and then do
|
||||
// a case-insensitive compare later.
|
||||
.name = attribute_part.token().ident().to_lowercase_string(),
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue