diff --git a/Libraries/LibWeb/CSS/Parser/ValueParsing.cpp b/Libraries/LibWeb/CSS/Parser/ValueParsing.cpp index bc4819bc42..2f92767f76 100644 --- a/Libraries/LibWeb/CSS/Parser/ValueParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/ValueParsing.cpp @@ -3678,9 +3678,17 @@ bool Parser::expand_variables(DOM::Element& element, Optionalis_unresolved()); TokenStream custom_property_tokens { custom_property_value->as_unresolved().values() }; + + auto dest_size_before = dest.size(); if (!expand_variables(element, pseudo_element, custom_property_name, dependencies, custom_property_tokens, dest)) return false; - continue; + + // If the size of dest has increased, then the custom property is not the initial guaranteed-invalid value. + // If it hasn't increased, then it is the initial guaranteed-invalid value, and thus we should move on to the fallback value. + if (dest_size_before < dest.size()) + continue; + + dbgln_if(CSS_PARSER_DEBUG, "CSSParser: Expanding custom property '{}' did not return any tokens, treating it as invalid and moving on to the fallback value.", custom_property_name); } // Use the provided fallback value, if any. diff --git a/Tests/LibWeb/Text/expected/css/var-uses-fallback-value-if-custom-property-is-empty.txt b/Tests/LibWeb/Text/expected/css/var-uses-fallback-value-if-custom-property-is-empty.txt new file mode 100644 index 0000000000..879e9020a5 --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/var-uses-fallback-value-if-custom-property-is-empty.txt @@ -0,0 +1 @@ +background-color: rgb(0, 128, 0) diff --git a/Tests/LibWeb/Text/input/css/var-uses-fallback-value-if-custom-property-is-empty.html b/Tests/LibWeb/Text/input/css/var-uses-fallback-value-if-custom-property-is-empty.html new file mode 100644 index 0000000000..ff37c55ec0 --- /dev/null +++ b/Tests/LibWeb/Text/input/css/var-uses-fallback-value-if-custom-property-is-empty.html @@ -0,0 +1,28 @@ + + +
+ +