diff --git a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp index 8a56ac35b9e..8ebd1a1f94a 100644 --- a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -747,12 +749,40 @@ GC::Ptr Parser::convert_to_property_rule(AtRule const& rule) } }); - // TODO: Parse the initial value using the syntax, if it's provided. - - if (syntax_maybe.has_value() && inherits_maybe.has_value()) { - return CSSPropertyRule::create(realm(), name, syntax_maybe.value(), inherits_maybe.value(), move(initial_value_maybe)); + // @property rules require a syntax and inherits descriptor; if either are missing, the entire rule is invalid and must be ignored. + if (!syntax_maybe.has_value() || syntax_maybe->is_empty() || !inherits_maybe.has_value()) { + return {}; } - return {}; + + auto parsing_params = CSS::Parser::ParsingParams { *document() }; + auto syntax_component_values = parse_component_values_list(parsing_params, syntax_maybe.value()); + auto maybe_syntax = parse_as_syntax(syntax_component_values); + + // If the provided string is not a valid syntax string (if it returns failure when consume + // a syntax definition is called on it), the descriptor is invalid and must be ignored. + if (!maybe_syntax) { + return {}; + } + // The initial-value descriptor is optional only if the syntax is the universal syntax definition, + // otherwise the descriptor is required; if it’s missing, the entire rule is invalid and must be ignored. + if (!initial_value_maybe && maybe_syntax->type() != CSS::Parser::SyntaxNode::NodeType::Universal) { + return {}; + } + + if (initial_value_maybe) { + initial_value_maybe = Web::CSS::Parser::parse_with_a_syntax(parsing_params, initial_value_maybe->tokenize(), *maybe_syntax); + // Otherwise, if the value of the syntax descriptor is not the universal syntax definition, + // the following conditions must be met for the @property rule to be valid: + // - The initial-value descriptor must be present. + // - The initial-value descriptor’s value must parse successfully according to the grammar specified by the syntax definition. + // - FIXME: The initial-value must be computationally independent. + + if (!initial_value_maybe || initial_value_maybe->is_guaranteed_invalid()) { + return {}; + } + } + + return CSSPropertyRule::create(realm(), name, syntax_maybe.value(), inherits_maybe.value(), move(initial_value_maybe)); } GC::Ptr Parser::convert_to_font_face_rule(AtRule const& rule) diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/at-property-cssom.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/at-property-cssom.txt new file mode 100644 index 00000000000..904e1801ea0 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/at-property-cssom.txt @@ -0,0 +1,44 @@ +Harness status: OK + +Found 39 tests + +39 Pass +Pass Rule for --no-descriptors is invalid +Pass Rule for --no-syntax is invalid +Pass Rule for --no-inherits is invalid +Pass Rule for --no-initial-color-value is invalid +Pass Rule for --syntax-only is invalid +Pass Rule for --inherits-only is invalid +Pass Rule for --initial-value-only is invalid +Pass Rule for --valid has expected cssText +Pass Rule for --valid-reverse has expected cssText +Pass Rule for --valid-universal has expected cssText +Pass Rule for --valid-whitespace has expected cssText +Pass Rule for --vALId has expected cssText +Pass Rule for --no-initial-universal-value has expected cssText +Pass Rule for --tab tab has expected cssText +Pass CSSRule.type returns 0 +Pass Rule for --valid returns expected value for CSSPropertyRule.name +Pass Rule for --valid-reverse returns expected value for CSSPropertyRule.name +Pass Rule for --valid-universal returns expected value for CSSPropertyRule.name +Pass Rule for --valid-whitespace returns expected value for CSSPropertyRule.name +Pass Rule for --vALId returns expected value for CSSPropertyRule.name +Pass Rule for --no-initial-universal-value returns expected value for CSSPropertyRule.name +Pass Rule for --valid returns expected value for CSSPropertyRule.syntax +Pass Rule for --valid-reverse returns expected value for CSSPropertyRule.syntax +Pass Rule for --valid-universal returns expected value for CSSPropertyRule.syntax +Pass Rule for --valid-whitespace returns expected value for CSSPropertyRule.syntax +Pass Rule for --vALId returns expected value for CSSPropertyRule.syntax +Pass Rule for --no-initial-universal-value returns expected value for CSSPropertyRule.syntax +Pass Rule for --valid returns expected value for CSSPropertyRule.inherits +Pass Rule for --valid-reverse returns expected value for CSSPropertyRule.inherits +Pass Rule for --valid-universal returns expected value for CSSPropertyRule.inherits +Pass Rule for --valid-whitespace returns expected value for CSSPropertyRule.inherits +Pass Rule for --vALId returns expected value for CSSPropertyRule.inherits +Pass Rule for --no-initial-universal-value returns expected value for CSSPropertyRule.inherits +Pass Rule for --valid returns expected value for CSSPropertyRule.initialValue +Pass Rule for --valid-reverse returns expected value for CSSPropertyRule.initialValue +Pass Rule for --valid-universal returns expected value for CSSPropertyRule.initialValue +Pass Rule for --valid-whitespace returns expected value for CSSPropertyRule.initialValue +Pass Rule for --vALId returns expected value for CSSPropertyRule.initialValue +Pass Rule for --no-initial-universal-value returns expected value for CSSPropertyRule.initialValue \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-values/attr-all-types.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/attr-all-types.txt index 9ad09a7bc4f..537678a1486 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-values/attr-all-types.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/attr-all-types.txt @@ -2,8 +2,8 @@ Harness status: OK Found 139 tests -130 Pass -9 Fail +128 Pass +11 Fail Pass CSS Values and Units Test: attr Fail CSS Values and Units Test: attr 1 Pass CSS Values and Units Test: attr 2 @@ -54,12 +54,12 @@ Pass CSS Values and Units Test: attr 46 Pass CSS Values and Units Test: attr 47 Pass CSS Values and Units Test: attr 48 Pass CSS Values and Units Test: attr 49 -Pass CSS Values and Units Test: attr 50 +Fail CSS Values and Units Test: attr 50 Fail CSS Values and Units Test: attr 51 Pass CSS Values and Units Test: attr 52 Pass CSS Values and Units Test: attr 53 Pass CSS Values and Units Test: attr 54 -Pass CSS Values and Units Test: attr 55 +Fail CSS Values and Units Test: attr 55 Pass CSS Values and Units Test: attr 56 Pass CSS Values and Units Test: attr 57 Pass CSS Values and Units Test: attr 58 diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-variables/variable-css-wide-keywords.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-variables/variable-css-wide-keywords.txt index 7d6b52b0698..ba07e6608b9 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-variables/variable-css-wide-keywords.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-variables/variable-css-wide-keywords.txt @@ -2,15 +2,15 @@ Harness status: OK Found 30 tests -11 Pass -19 Fail +9 Pass +21 Fail Pass `initial` as a value for an unregistered custom property Pass `inherit` as a value for an unregistered custom property Pass `unset` as a value for an unregistered custom property Fail `revert` as a value for an unregistered custom property Pass `revert-layer` as a value for an unregistered custom property -Pass `initial` as a value for a non-inheriting registered custom property -Pass `initial` as a value for an inheriting registered custom property +Fail `initial` as a value for a non-inheriting registered custom property +Fail `initial` as a value for an inheriting registered custom property Pass `inherit` as a value for a non-inheriting registered custom property Pass `inherit` as a value for an inheriting registered custom property Fail `unset` as a value for a non-inheriting registered custom property diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-properties-values-api/at-property-cssom.html b/Tests/LibWeb/Text/input/wpt-import/css/css-properties-values-api/at-property-cssom.html new file mode 100644 index 00000000000..56d4ea7a27a --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-properties-values-api/at-property-cssom.html @@ -0,0 +1,191 @@ + + + + + +