Skip to content

Commit cb37737

Browse files
committed
LibWeb/CSS: Handle whitespace properly in font properties
1 parent 372ae7c commit cb37737

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,11 +2680,13 @@ RefPtr<StyleValue const> Parser::parse_font_value(TokenStream<ComponentValue>& t
26802680
// font-variant and font-width aren't included because we have special parsing rules for them in font.
26812681
auto remaining_longhands = Vector { PropertyID::FontSize, PropertyID::FontStyle, PropertyID::FontWeight };
26822682
auto transaction = tokens.begin_transaction();
2683+
tokens.discard_whitespace();
26832684

26842685
while (tokens.has_next_token()) {
26852686
if (tokens.next_token().is_ident("normal"sv)) {
26862687
normal_count++;
2687-
tokens.discard_a_token();
2688+
tokens.discard_a_token(); // normal
2689+
tokens.discard_whitespace();
26882690
continue;
26892691
}
26902692

@@ -2710,6 +2712,7 @@ RefPtr<StyleValue const> Parser::parse_font_value(TokenStream<ComponentValue>& t
27102712
property_initial_value(PropertyID::FontVariantNumeric),
27112713
property_initial_value(PropertyID::FontVariantPosition),
27122714
});
2715+
tokens.discard_whitespace();
27132716
continue;
27142717
}
27152718

@@ -2721,6 +2724,7 @@ RefPtr<StyleValue const> Parser::parse_font_value(TokenStream<ComponentValue>& t
27212724
if (keyword_to_font_width(keyword->to_keyword()).has_value()) {
27222725
font_width_transaction.commit();
27232726
font_width = keyword.release_nonnull();
2727+
tokens.discard_whitespace();
27242728
continue;
27252729
}
27262730
}
@@ -2738,12 +2742,14 @@ RefPtr<StyleValue const> Parser::parse_font_value(TokenStream<ComponentValue>& t
27382742
font_size = value.release_nonnull();
27392743

27402744
// Consume `/ line-height` if present
2745+
tokens.discard_whitespace();
27412746
if (tokens.next_token().is_delim('/')) {
2742-
tokens.discard_a_token();
2747+
tokens.discard_a_token(); // /
27432748
auto maybe_line_height = parse_css_value_for_property(PropertyID::LineHeight, tokens);
27442749
if (!maybe_line_height)
27452750
return nullptr;
27462751
line_height = maybe_line_height.release_nonnull();
2752+
tokens.discard_whitespace();
27472753
}
27482754

27492755
// Consume font-families
@@ -2752,16 +2758,19 @@ RefPtr<StyleValue const> Parser::parse_font_value(TokenStream<ComponentValue>& t
27522758
if (!maybe_font_families || tokens.has_next_token())
27532759
return nullptr;
27542760
font_families = maybe_font_families.release_nonnull();
2761+
tokens.discard_whitespace();
27552762
continue;
27562763
}
27572764
case PropertyID::FontStyle: {
27582765
VERIFY(!font_style);
27592766
font_style = FontStyleStyleValue::create(*keyword_to_font_style(value.release_nonnull()->to_keyword()));
2767+
tokens.discard_whitespace();
27602768
continue;
27612769
}
27622770
case PropertyID::FontWeight: {
27632771
VERIFY(!font_weight);
27642772
font_weight = value.release_nonnull();
2773+
tokens.discard_whitespace();
27652774
continue;
27662775
}
27672776
default:

Libraries/LibWeb/CSS/Properties.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,6 @@
18681868
]
18691869
},
18701870
"font": {
1871-
"strip-whitespace": true,
18721871
"inherited": true,
18731872
"initial": "normal medium serif",
18741873
"__comment": "FIXME: Handle properties that are reset implicitly. https://drafts.csswg.org/css-fonts/#reset-implicitly",
@@ -1883,7 +1882,6 @@
18831882
]
18841883
},
18851884
"font-family": {
1886-
"strip-whitespace": true,
18871885
"animation-type": "discrete",
18881886
"inherited": true,
18891887
"initial": "serif",
@@ -1894,7 +1892,6 @@
18941892
]
18951893
},
18961894
"font-feature-settings": {
1897-
"strip-whitespace": true,
18981895
"animation-type": "discrete",
18991896
"inherited": true,
19001897
"initial": "normal",
@@ -1910,7 +1907,6 @@
19101907
]
19111908
},
19121909
"font-kerning": {
1913-
"strip-whitespace": true,
19141910
"animation-type": "discrete",
19151911
"inherited": true,
19161912
"initial": "auto",
@@ -1919,7 +1915,6 @@
19191915
]
19201916
},
19211917
"font-language-override": {
1922-
"strip-whitespace": true,
19231918
"animation-type": "discrete",
19241919
"inherited": true,
19251920
"initial": "normal",
@@ -1931,7 +1926,6 @@
19311926
]
19321927
},
19331928
"font-size": {
1934-
"strip-whitespace": true,
19351929
"animation-type": "by-computed-value",
19361930
"inherited": true,
19371931
"initial": "medium",
@@ -1953,7 +1947,6 @@
19531947
"legacy-alias-for": "font-width"
19541948
},
19551949
"font-style": {
1956-
"strip-whitespace": true,
19571950
"animation-type": "custom",
19581951
"inherited": true,
19591952
"initial": "normal",
@@ -1963,7 +1956,6 @@
19631956
]
19641957
},
19651958
"font-variant": {
1966-
"strip-whitespace": true,
19671959
"inherited": true,
19681960
"initial": "normal",
19691961
"longhands": [
@@ -1980,7 +1972,6 @@
19801972
]
19811973
},
19821974
"font-variant-alternates": {
1983-
"strip-whitespace": true,
19841975
"animation-type": "discrete",
19851976
"inherited": true,
19861977
"initial": "normal",
@@ -1989,7 +1980,6 @@
19891980
]
19901981
},
19911982
"font-variant-caps": {
1992-
"strip-whitespace": true,
19931983
"animation-type": "discrete",
19941984
"inherited": true,
19951985
"initial": "normal",
@@ -1998,7 +1988,6 @@
19981988
]
19991989
},
20001990
"font-variant-east-asian": {
2001-
"strip-whitespace": true,
20021991
"animation-type": "discrete",
20031992
"inherited": true,
20041993
"initial": "normal",
@@ -2007,7 +1996,6 @@
20071996
]
20081997
},
20091998
"font-variant-emoji": {
2010-
"strip-whitespace": true,
20111999
"animation-type": "discrete",
20122000
"inherited": true,
20132001
"initial": "normal",
@@ -2016,7 +2004,6 @@
20162004
]
20172005
},
20182006
"font-variant-ligatures": {
2019-
"strip-whitespace": true,
20202007
"animation-type": "discrete",
20212008
"inherited": true,
20222009
"initial": "normal",
@@ -2025,7 +2012,6 @@
20252012
]
20262013
},
20272014
"font-variant-numeric": {
2028-
"strip-whitespace": true,
20292015
"animation-type": "discrete",
20302016
"inherited": true,
20312017
"initial": "normal",
@@ -2034,7 +2020,6 @@
20342020
]
20352021
},
20362022
"font-variant-position": {
2037-
"strip-whitespace": true,
20382023
"animation-type": "discrete",
20392024
"inherited": true,
20402025
"initial": "normal",
@@ -2043,7 +2028,6 @@
20432028
]
20442029
},
20452030
"font-variation-settings": {
2046-
"strip-whitespace": true,
20472031
"animation-type": "custom",
20482032
"inherited": true,
20492033
"initial": "normal",
@@ -2057,7 +2041,6 @@
20572041
]
20582042
},
20592043
"font-weight": {
2060-
"strip-whitespace": true,
20612044
"animation-type": "by-computed-value",
20622045
"inherited": true,
20632046
"initial": "normal",
@@ -2072,7 +2055,6 @@
20722055
]
20732056
},
20742057
"font-width": {
2075-
"strip-whitespace": true,
20762058
"animation-type": "by-computed-value",
20772059
"inherited": true,
20782060
"initial": "normal",

0 commit comments

Comments
 (0)