mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:58:12 +00:00
LibWeb: Support more advanced selectors in document.querySelectorAll()
I made some mistakes in the selector parsing code. It's now able to parse selectors composed of multiple complex selectors, instead of just one complex selector.
This commit is contained in:
parent
c1c56b1131
commit
06aec9667e
4 changed files with 21 additions and 17 deletions
|
@ -267,13 +267,10 @@ public:
|
|||
|
||||
Optional<Selector::SimpleSelector> parse_simple_selector()
|
||||
{
|
||||
if (!peek())
|
||||
return {};
|
||||
|
||||
if (consume_whitespace_or_comments())
|
||||
return {};
|
||||
|
||||
if (peek() == '{' || peek() == ',' || is_combinator(peek()))
|
||||
if (!peek() || peek() == '{' || peek() == ',' || is_combinator(peek()))
|
||||
return {};
|
||||
|
||||
Selector::SimpleSelector::Type type;
|
||||
|
@ -447,7 +444,7 @@ public:
|
|||
if (complex_selector.has_value())
|
||||
complex_selectors.append(complex_selector.value());
|
||||
consume_whitespace_or_comments();
|
||||
if (peek() == ',' || peek() == '{')
|
||||
if (!peek() || peek() == ',' || peek() == '{')
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -456,7 +453,15 @@ public:
|
|||
complex_selectors.first().relation = Selector::ComplexSelector::Relation::None;
|
||||
|
||||
current_rule.selectors.append(Selector(move(complex_selectors)));
|
||||
};
|
||||
}
|
||||
|
||||
Optional<Selector> parse_individual_selector()
|
||||
{
|
||||
parse_selector();
|
||||
if (current_rule.selectors.is_empty())
|
||||
return {};
|
||||
return current_rule.selectors.last();
|
||||
}
|
||||
|
||||
void parse_selector_list()
|
||||
{
|
||||
|
@ -664,11 +669,7 @@ private:
|
|||
Optional<Selector> parse_selector(const StringView& selector_text)
|
||||
{
|
||||
CSSParser parser(selector_text);
|
||||
auto complex_selector = parser.parse_complex_selector();
|
||||
if (!complex_selector.has_value())
|
||||
return {};
|
||||
complex_selector.value().relation = Selector::ComplexSelector::Relation::None;
|
||||
return Selector({ complex_selector.value() });
|
||||
return parser.parse_individual_selector();
|
||||
}
|
||||
|
||||
RefPtr<StyleSheet> parse_css(const StringView& css)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue