diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index 069cbc06b6b..d948eae5344 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -192,14 +192,17 @@ RefPtr Parser::parse_as_supports() template RefPtr Parser::parse_a_supports(TokenStream& tokens) { + auto transaction = tokens.begin_transaction(); auto component_values = parse_a_list_of_component_values(tokens); TokenStream token_stream { component_values }; m_rule_context.append(RuleContext::SupportsCondition); auto maybe_condition = parse_boolean_expression(token_stream, MatchResult::False, [this](auto& tokens) { return parse_supports_feature(tokens); }); m_rule_context.take_last(); token_stream.discard_whitespace(); - if (maybe_condition && !token_stream.has_next_token()) + if (maybe_condition && !token_stream.has_next_token()) { + transaction.commit(); return Supports::create(maybe_condition.release_nonnull()); + } return {}; } diff --git a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp index 2c76197d269..a088669cb67 100644 --- a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp @@ -242,9 +242,8 @@ GC::Ptr Parser::convert_to_import_rule(AtRule const& rule) if (tokens.next_token().is_function("supports"sv)) { auto component_value = tokens.consume_a_token(); TokenStream supports_tokens { component_value.function().value }; - if (supports_tokens.next_token().is_block()) { - supports = parse_a_supports(supports_tokens); - } else { + supports = parse_a_supports(supports_tokens); + if (!supports) { m_rule_context.append(RuleContext::SupportsCondition); auto declaration = consume_a_declaration(supports_tokens); m_rule_context.take_last(); diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/parsing/supports-import-parsing.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/parsing/supports-import-parsing.txt index b58337dfe22..046ae1cdb5f 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/parsing/supports-import-parsing.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/parsing/supports-import-parsing.txt @@ -2,13 +2,13 @@ Harness status: OK Found 22 tests -9 Pass -13 Fail +16 Pass +6 Fail Pass @import url("nonexist.css") supports(); should be an invalid import rule due to an invalid supports() declaration Pass @import url("nonexist.css") supports(foo: bar); should be an invalid import rule due to an invalid supports() declaration Fail @import url("nonexist.css") supports(display:block); should be a valid supports() import rule Fail @import url("nonexist.css") supports((display:flex)); should be a valid supports() import rule -Fail @import url("nonexist.css") supports(not (display: flex)); should be a valid supports() import rule +Pass @import url("nonexist.css") supports(not (display: flex)); should be a valid supports() import rule Pass @import url("nonexist.css") supports((display: flex) and (display: block)); should be a valid supports() import rule Pass @import url("nonexist.css") supports((display: flex) or (display: block)); should be a valid supports() import rule Pass @import url("nonexist.css") supports((display: flex) or (foo: bar)); should be a valid supports() import rule @@ -17,12 +17,12 @@ Pass @import url("nonexist.css") layer supports(); should be an invalid import r Pass @import url("nonexist.css") layer supports(foo: bar); should be an invalid import rule due to an invalid supports() declaration Fail @import url("nonexist.css") layer(A) supports((display: flex) or (foo: bar)); should be a valid supports() import rule Fail @import url("nonexist.css") layer(A.B) supports((display: flex) and (foo: bar)); should be a valid supports() import rule -Fail @import url("nonexist.css") supports(selector(a)); should be a valid supports() import rule -Fail @import url("nonexist.css") supports(selector(p a)); should be a valid supports() import rule -Fail @import url("nonexist.css") supports(selector(p > a)); should be a valid supports() import rule -Fail @import url("nonexist.css") supports(selector(p + a)); should be a valid supports() import rule -Fail @import url("nonexist.css") supports(font-tech(color-colrv1)); should be a valid supports() import rule -Fail @import url("nonexist.css") supports(font-format(opentype)); should be a valid supports() import rule +Pass @import url("nonexist.css") supports(selector(a)); should be a valid supports() import rule +Pass @import url("nonexist.css") supports(selector(p a)); should be a valid supports() import rule +Pass @import url("nonexist.css") supports(selector(p > a)); should be a valid supports() import rule +Pass @import url("nonexist.css") supports(selector(p + a)); should be a valid supports() import rule +Pass @import url("nonexist.css") supports(font-tech(color-colrv1)); should be a valid supports() import rule +Pass @import url("nonexist.css") supports(font-format(opentype)); should be a valid supports() import rule Fail @import url(nonexist.css) supports(display:block); should be a valid supports() import rule Fail @import "nonexist.css" supports(display:block); should be a valid supports() import rule Pass @import url("nonexist.css") supports; should still be a valid import rule with an invalid supports() declaration \ No newline at end of file