LibWeb: Only match alternative syntax if entire stream consumed

Previously we would consider an alternative syntax child to be a match
as long as parsing produced a value, even if there were trailing tokens
(which would later invalidate it within `parse_with_a_syntax`). This
meant that we wouldn't consider later alternatives which may actually
produce a valid match.
This commit is contained in:
Callum Law
2026-03-08 17:28:28 +13:00
committed by Sam Atkins
parent 614a5cf33e
commit 283f8e46a4
Notes: github-actions[bot] 2026-03-26 01:13:15 +00:00
2 changed files with 15 additions and 11 deletions

View File

@@ -290,8 +290,12 @@ RefPtr<StyleValue const> Parser::parse_according_to_syntax_node(TokenStream<Comp
case SyntaxNode::NodeType::Alternatives: {
auto const& alternatives_node = as<AlternativesSyntaxNode>(syntax_node);
for (auto const& child : alternatives_node.children()) {
if (auto result = parse_according_to_syntax_node(tokens, *child)) {
transaction.commit();
auto alternative_transaction = transaction.create_child();
auto result = parse_according_to_syntax_node(tokens, *child);
tokens.discard_whitespace();
if (result && tokens.is_empty()) {
alternative_transaction.commit();
return result.release_nonnull();
}
}