Skip to content

Commit

Permalink
LibWeb: Allow font-family names to start with -
Browse files Browse the repository at this point in the history
We achieve this by making properties that accept a custom-ident value
skip the "someone else's vendor prefix" check for values that start with
a `-` character.

This fixes an issue where e.g `font:family: Arial, -apple-system` would
be rejected by the parser completely. We now treat `-apple-system` like
an identifier in such cases.

Also add `valid-types` metadata for the `font-family` property so this
actually works. :^)
  • Loading branch information
awesomekling committed Jul 6, 2023
1 parent c1da8d7 commit d955876
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
serif, -apple-system
9 changes: 9 additions & 0 deletions Tests/LibWeb/Text/input/css/font-family-with-dash-prefix.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script src="../include.js"></script>
<script>
test(() => {
const e = document.createElement("div");
e.style.fontFamily = 'sans-serif';
e.style.fontFamily = 'serif, -apple-system';
println(e.style.fontFamily);
});
</script>
3 changes: 2 additions & 1 deletion Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7928,6 +7928,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
m_context.set_current_property_id(property_id);
Vector<ComponentValue> component_values;
bool contains_var_or_attr = false;
bool const property_accepts_custom_ident = property_accepts_type(property_id, ValueType::CustomIdent);

while (tokens.has_next_token()) {
auto const& token = tokens.next_token();
Expand All @@ -7941,7 +7942,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
if (token.is(Token::Type::Whitespace))
continue;

if (token.is(Token::Type::Ident) && has_ignored_vendor_prefix(token.token().ident()))
if (!property_accepts_custom_ident && token.is(Token::Type::Ident) && has_ignored_vendor_prefix(token.token().ident()))
return ParseError::IncludesIgnoredVendorPrefix;
}

Expand Down
6 changes: 5 additions & 1 deletion Userland/Libraries/LibWeb/CSS/Properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,11 @@
},
"font-family": {
"inherited": true,
"initial": "sans-serif"
"initial": "sans-serif",
"valid-types": [
"custom-ident",
"string"
]
},
"font-size": {
"inherited": true,
Expand Down

0 comments on commit d955876

Please sign in to comment.