LibWeb: Clamp calc()'d shadow blur radius to positive values

This commit is contained in:
Callum Law 2025-09-16 10:50:37 +12:00 committed by Sam Atkins
parent 19e3ddc0c6
commit 004bd3dc8f
5 changed files with 8 additions and 4 deletions

View File

@ -1285,7 +1285,7 @@ Vector<ShadowData> ComputedProperties::shadow(PropertyID property_id, Layout::No
if (value->is_length())
return value->as_length().length();
if (value->is_calculated())
return value->as_calculated().resolve_length_deprecated({ .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) });
return value->as_calculated().resolve_length({ .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) });
return {};
};

View File

@ -551,6 +551,7 @@ private:
DescriptorID descriptor;
};
enum SpecialContext : u8 {
ShadowBlurRadius,
TranslateZArgument
};
using ValueParsingContext = Variant<PropertyID, FunctionContext, DescriptorContext, SpecialContext>;

View File

@ -2111,7 +2111,9 @@ RefPtr<StyleValue const> Parser::parse_single_shadow_value(TokenStream<Component
if (!tokens.has_next_token())
break;
m_value_context.append(SpecialContext::ShadowBlurRadius);
auto maybe_blur_radius = parse_length_value(tokens);
m_value_context.take_last();
if (!maybe_blur_radius)
continue;
blur_radius = maybe_blur_radius;

View File

@ -4107,6 +4107,8 @@ RefPtr<StyleValue const> Parser::parse_calculated_value(ComponentValue const& co
},
[](SpecialContext special_context) -> Optional<CalculationContext> {
switch (special_context) {
case SpecialContext::ShadowBlurRadius:
return CalculationContext { .accepted_type_ranges = { { ValueType::Length, { 0, NumericLimits<float>::max() } } } };
case SpecialContext::TranslateZArgument:
// Percentages are disallowed for the Z axis
return CalculationContext {};

View File

@ -2,12 +2,11 @@ Harness status: OK
Found 7 tests
6 Pass
1 Fail
7 Pass
Pass Property text-shadow value 'none'
Pass Property text-shadow value '10px 20px'
Pass Property text-shadow value 'red 10px 20px 30px'
Pass Property text-shadow value 'calc(0.5em + 10px) calc(0.5em + 10px) calc(0.5em + 10px)'
Fail Property text-shadow value 'calc(-0.5em + 10px) calc(-0.5em + 10px) calc(-0.5em + 10px)'
Pass Property text-shadow value 'calc(-0.5em + 10px) calc(-0.5em + 10px) calc(-0.5em + 10px)'
Pass Property text-shadow value '10px 20px, 30px 40px'
Pass Property text-shadow value 'lime 10px 20px 30px, red 40px 50px'