LibWeb: Handle serialization of invalid font-variant in all contexts

Previously as we handled this in `get_property_internal` there were some
contexts that we missed, for instance `CSSStyleProperties::serialized`.
This commit is contained in:
Callum Law 2025-07-10 17:04:57 +12:00 committed by Sam Atkins
commit 09a5c04e5c
Notes: github-actions[bot] 2025-07-15 13:27:42 +00:00
4 changed files with 21 additions and 34 deletions

View file

@ -509,40 +509,6 @@ Optional<StyleProperty> CSSStyleProperties::get_property_internal(PropertyID pro
auto left = get_property_internal(PropertyID::BorderLeftWidth); auto left = get_property_internal(PropertyID::BorderLeftWidth);
return style_property_for_sided_shorthand(property_id, top, right, bottom, left); return style_property_for_sided_shorthand(property_id, top, right, bottom, left);
} }
case PropertyID::FontVariant: {
auto ligatures = get_property_internal(PropertyID::FontVariantLigatures);
auto caps = get_property_internal(PropertyID::FontVariantCaps);
auto alternates = get_property_internal(PropertyID::FontVariantAlternates);
auto numeric = get_property_internal(PropertyID::FontVariantNumeric);
auto east_asian = get_property_internal(PropertyID::FontVariantEastAsian);
auto position = get_property_internal(PropertyID::FontVariantPosition);
auto emoji = get_property_internal(PropertyID::FontVariantEmoji);
if (!ligatures.has_value() || !caps.has_value() || !alternates.has_value() || !numeric.has_value() || !east_asian.has_value() || !position.has_value() || !emoji.has_value())
return {};
if (ligatures->important != caps->important || ligatures->important != alternates->important || ligatures->important != numeric->important || ligatures->important != east_asian->important || ligatures->important != position->important || ligatures->important != emoji->important)
return {};
// If ligatures is `none` and any other value isn't `normal`, that's invalid.
if (ligatures->value->to_keyword() == Keyword::None
&& (caps->value->to_keyword() != Keyword::Normal
|| alternates->value->to_keyword() != Keyword::Normal
|| numeric->value->to_keyword() != Keyword::Normal
|| east_asian->value->to_keyword() != Keyword::Normal
|| position->value->to_keyword() != Keyword::Normal
|| emoji->value->to_keyword() != Keyword::Normal)) {
return {};
}
return StyleProperty {
.important = ligatures->important,
.property_id = property_id,
.value = ShorthandStyleValue::create(property_id,
{ PropertyID::FontVariantLigatures, PropertyID::FontVariantCaps, PropertyID::FontVariantAlternates, PropertyID::FontVariantNumeric, PropertyID::FontVariantEastAsian, PropertyID::FontVariantPosition, PropertyID::FontVariantEmoji },
{ ligatures->value, caps->value, alternates->value, numeric->value, east_asian->value, position->value, emoji->value })
};
}
case PropertyID::Margin: { case PropertyID::Margin: {
auto top = get_property_internal(PropertyID::MarginTop); auto top = get_property_internal(PropertyID::MarginTop);
auto right = get_property_internal(PropertyID::MarginRight); auto right = get_property_internal(PropertyID::MarginRight);

View file

@ -344,6 +344,10 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const
auto position = longhand(PropertyID::FontVariantPosition); auto position = longhand(PropertyID::FontVariantPosition);
auto emoji = longhand(PropertyID::FontVariantEmoji); auto emoji = longhand(PropertyID::FontVariantEmoji);
// If ligatures is `none` and any other value isn't `normal`, that's invalid.
if (ligatures->to_keyword() == Keyword::None && !first_is_equal_to_all_of(Keyword::Normal, caps->to_keyword(), alternates->to_keyword(), numeric->to_keyword(), east_asian->to_keyword(), position->to_keyword(), emoji->to_keyword()))
return ""_string;
Vector<String> values; Vector<String> values;
if (ligatures->to_keyword() != Keyword::Normal) if (ligatures->to_keyword() != Keyword::Normal)
values.append(ligatures->to_string(mode)); values.append(ligatures->to_string(mode));

View file

@ -0,0 +1 @@
#foo { font-variant-alternates: normal; font-variant-east-asian: normal; font-variant-emoji: normal; font-variant-numeric: normal; font-variant-position: normal; font-variant-ligatures: none; font-variant-caps: all-petite-caps; }

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<style>
#foo {
font-variant: normal;
font-variant-ligatures: none;
font-variant-caps: all-petite-caps;
}
</style>
<script src="../include.js"></script>
<script>
test(() => {
println(document.styleSheets[0].cssRules[0].cssText);
});
</script>
</html>