LibWeb: Clamp computed value for font-style oblique angle

Values outside [-90deg,90deg] are invalid and should be clamped
This commit is contained in:
Callum Law 2025-09-03 19:30:32 +12:00 committed by Sam Atkins
commit e17d91780d
Notes: github-actions[bot] 2025-09-19 09:07:38 +00:00
5 changed files with 13 additions and 8 deletions

View file

@ -551,6 +551,7 @@ private:
DescriptorID descriptor;
};
enum SpecialContext : u8 {
FontStyleObliqueAngle,
ShadowBlurRadius,
TranslateZArgument
};

View file

@ -2979,6 +2979,7 @@ RefPtr<StyleValue const> Parser::parse_font_style_value(TokenStream<ComponentVal
auto font_style = keyword_to_font_style(keyword_value->to_keyword());
VERIFY(font_style.has_value());
if (tokens.has_next_token() && keyword_value->to_keyword() == Keyword::Oblique) {
auto context_guard = push_temporary_value_parsing_context(SpecialContext::FontStyleObliqueAngle);
if (auto angle_value = parse_angle_value(tokens)) {
if (angle_value->is_angle()) {
auto angle = angle_value->as_angle().angle();

View file

@ -4107,6 +4107,10 @@ RefPtr<StyleValue const> Parser::parse_calculated_value(ComponentValue const& co
},
[](SpecialContext special_context) -> Optional<CalculationContext> {
switch (special_context) {
case SpecialContext::FontStyleObliqueAngle:
return CalculationContext {
.accepted_type_ranges = { { ValueType::Angle, { -90, 90 } } }
};
case SpecialContext::ShadowBlurRadius:
return CalculationContext { .accepted_type_ranges = { { ValueType::Length, { 0, NumericLimits<float>::max() } } } };
case SpecialContext::TranslateZArgument:

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 17 tests
14 Pass
3 Fail
16 Pass
1 Fail
Pass Property font-style value 'normal'
Pass Property font-style value 'italic'
Pass Property font-style value 'oblique'
@ -17,7 +17,7 @@ Pass Property font-style value 'oblique -90deg'
Pass Property font-style value 'oblique 90deg'
Pass Property font-style value 'oblique 10grad'
Pass Property font-style value 'oblique calc(90deg)'
Fail Property font-style value 'oblique calc(100deg)'
Fail Property font-style value 'oblique calc(-100deg)'
Pass Property font-style value 'oblique calc(100deg)'
Pass Property font-style value 'oblique calc(-100deg)'
Pass Property font-style value 'oblique calc(30deg * 2)'
Fail Property font-style value 'oblique calc(30deg + (sign(20cqw - 10px) * 5deg))'

View file

@ -2,8 +2,7 @@ Harness status: OK
Found 43 tests
41 Pass
2 Fail
43 Pass
Pass Font-style (supports): 'italic' is valid
Pass Font-style (supports): 'italic' followed by angle is invalid
Pass Font-style (supports): 'italic' followed by non-number is invalid
@ -44,6 +43,6 @@ Pass Font-style (computed): 'oblique' followed by maxumum 90 degree angle is val
Pass Font-style (computed): 'oblique' followed by minimum -90 degree angle is valid
Pass Font-style (computed): 'oblique' followed by positive angle is valid
Pass Font-style (computed): 'oblique' followed by calc is valid
Fail Font-style (computed): 'oblique' followed by calc is valid even if it must be clamped (no computation)
Fail Font-style (computed): 'oblique' followed by calc is valid even if it must be clamped (with computation)
Pass Font-style (computed): 'oblique' followed by calc is valid even if it must be clamped (no computation)
Pass Font-style (computed): 'oblique' followed by calc is valid even if it must be clamped (with computation)
Pass Font-style (computed): 'oblique' followed by calc is valid even if it mixes units (with computation)