Skip to content

Truly independent web browser

LibWeb: Restrict typed shape thresholds to numbers

Andreas Kling7973bc4d97ff
diff --git a/Libraries/LibWeb/CSS/StylePropertyMap.cpp b/Libraries/LibWeb/CSS/StylePropertyMap.cpp
index b56923516cb..0344a5ca2c1 100644
--- a/Libraries/LibWeb/CSS/StylePropertyMap.cpp
+++ b/Libraries/LibWeb/CSS/StylePropertyMap.cpp
@@ -83,6 +83,10 @@ static WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> create_an_internal_r
if (auto const* css_style_value = value.get_pointer<GC::Ref<CSSStyleValue>>();
css_style_value && is<CSSNumericValue>(**css_style_value) && !property.is_custom_property()) {
+ // INTEROP: Shape image thresholds accept typed numbers but not typed percentages.
+ if (property.id() == PropertyID::ShapeImageThreshold && !as<CSSNumericValue>(**css_style_value).type().matches_number({}))
+ return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Shape image thresholds require a number"_utf16 };
+
// https://drafts.css-houdini.org/css-typed-om-1/#create-an-internal-representation
// If value does not match the grammar of a list-valued property iteration of property, throw a TypeError.
// NB: A property's component types do not establish that a numeric value alone matches its whole grammar.
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/shape-image-threshold.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/shape-image-threshold.txt
index f1f9ae88a68..2c8526c6851 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/shape-image-threshold.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/shape-image-threshold.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 31 tests
-27 Pass
-4 Fail
+31 Pass
Pass Can set 'shape-image-threshold' to CSS-wide keywords: initial
Pass Can set 'shape-image-threshold' to CSS-wide keywords: inherit
Pass Can set 'shape-image-threshold' to CSS-wide keywords: unset
@@ -17,10 +16,10 @@ Pass Setting 'shape-image-threshold' to a length: 0px throws TypeError
Pass Setting 'shape-image-threshold' to a length: -3.14em throws TypeError
Pass Setting 'shape-image-threshold' to a length: 3.14cm throws TypeError
Pass Setting 'shape-image-threshold' to a length: calc(0px + 0em) throws TypeError
-Fail Setting 'shape-image-threshold' to a percent: 0% throws TypeError
-Fail Setting 'shape-image-threshold' to a percent: -3.14% throws TypeError
-Fail Setting 'shape-image-threshold' to a percent: 3.14% throws TypeError
-Fail Setting 'shape-image-threshold' to a percent: calc(0% + 0%) throws TypeError
+Pass Setting 'shape-image-threshold' to a percent: 0% throws TypeError
+Pass Setting 'shape-image-threshold' to a percent: -3.14% throws TypeError
+Pass Setting 'shape-image-threshold' to a percent: 3.14% throws TypeError
+Pass Setting 'shape-image-threshold' to a percent: calc(0% + 0%) throws TypeError
Pass Setting 'shape-image-threshold' to a time: 0s throws TypeError
Pass Setting 'shape-image-threshold' to a time: -3.14ms throws TypeError
Pass Setting 'shape-image-threshold' to a time: 3.14s throws TypeError