diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-07-02 13:01:38 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 23:19:56 +0200 |
commit | f9ffa34622643147fe759d9d7bced2093d4921e1 (patch) | |
tree | d11fad0118ac846a976aff8006edf2ed1a858c0d /Userland/Libraries/LibWeb/CSS | |
parent | 9115c23bd5c871fea57b13a9bba44e5553962e06 (diff) | |
download | serenity-f9ffa34622643147fe759d9d7bced2093d4921e1.zip |
LibWeb: Remove broken CSS:Parser::is_combinator()
A single DELIM token is only one character long, so the check for
a "||" DELIM didn't work. We now just do the check inline.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 33 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Parser/Parser.h | 1 |
2 files changed, 19 insertions, 15 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 2a4d65dea7..637ae34b2c 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -318,20 +318,30 @@ Vector<CSS::Selector::ComplexSelector> Parser::parse_selectors(Vector<StyleCompo auto parse_complex_selector = [&]() -> Optional<CSS::Selector::ComplexSelector> { auto relation = CSS::Selector::ComplexSelector::Relation::Descendant; + if (index >= parts.size()) + return {}; + auto current_value = parts.at(index); if (current_value.is(Token::TokenType::Delim)) { auto delim = current_value.token().delim(); - if (is_combinator(delim)) { - if (delim == ">") { - relation = CSS::Selector::ComplexSelector::Relation::ImmediateChild; - } else if (delim == "+") { - relation = CSS::Selector::ComplexSelector::Relation::AdjacentSibling; - } else if (delim == "~") { - relation = CSS::Selector::ComplexSelector::Relation::GeneralSibling; - } else if (delim == "||") { + if (delim == ">") { + relation = CSS::Selector::ComplexSelector::Relation::ImmediateChild; + index++; + } else if (delim == "+") { + relation = CSS::Selector::ComplexSelector::Relation::AdjacentSibling; + index++; + } else if (delim == "~") { + relation = CSS::Selector::ComplexSelector::Relation::GeneralSibling; + index++; + } else if (delim == "|") { + if (index + 1 >= parts.size()) + return {}; + + auto next = parts.at(index + 1); + if (next.is(Token::TokenType::Delim) && next.token().delim() == "|") { relation = CSS::Selector::ComplexSelector::Relation::Column; + index += 2; } - index++; } } @@ -386,11 +396,6 @@ void Parser::reconsume_current_input_token() --m_iterator_offset; } -bool Parser::is_combinator(String input) -{ - return input == ">" || input == "+" || input == "~" || input == "||"; -} - NonnullRefPtrVector<QualifiedStyleRule> Parser::consume_a_list_of_rules(bool top_level) { NonnullRefPtrVector<QualifiedStyleRule> rules; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index 6686f22c0f..db5b997b48 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -69,7 +69,6 @@ private: Token peek_token(); Token current_token(); void reconsume_current_input_token(); - bool is_combinator(String); NonnullRefPtrVector<QualifiedStyleRule> consume_a_list_of_rules(bool top_level); NonnullRefPtr<AtStyleRule> consume_an_at_rule(); |