Truly independent web browser
LibWeb: Validate numeric values against complete CSS grammars
Andreas Kling86b8d5eb63c0
diff --git a/Libraries/LibWeb/CSS/StylePropertyMap.cpp b/Libraries/LibWeb/CSS/StylePropertyMap.cppindex ae74805242f..b56923516cb 100644--- a/Libraries/LibWeb/CSS/StylePropertyMap.cpp+++ b/Libraries/LibWeb/CSS/StylePropertyMap.cpp@@ -6,6 +6,7 @@#include "StylePropertyMap.h"#include <LibGC/Heap.h>+#include <LibWeb/CSS/CSSNumericValue.h>#include <LibWeb/CSS/CSSStyleDeclaration.h>#include <LibWeb/CSS/CSSStyleValue.h>#include <LibWeb/CSS/CSSUnparsedValue.h>@@ -80,6 +81,16 @@ static WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> create_an_internal_rreturn result.get<GC::Ref<CSSStyleValue>>()->create_an_internal_representation(property, CSSStyleValue::PerformTypeCheck::Yes);}));+ if (auto const* css_style_value = value.get_pointer<GC::Ref<CSSStyleValue>>();+ css_style_value && is<CSSNumericValue>(**css_style_value) && !property.is_custom_property()) {+ // 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.+ auto parsed_value = parse_css_value(Parser::ParsingParams {}, internal_representation->to_utf16_string(SerializationMode::Normal), property.id());+ if (!parsed_value)+ return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Numeric value does not match the property's grammar"_utf16 };+ }+// AD-HOC: Our parser represents a text-indent that is just a length-percentage as a text-indent value, and style// computation expects that.if (property.id() == PropertyID::TextIndentdiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-increment.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-increment.txtindex 762d8d5fc59..7ca08ea1ba0 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-increment.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-increment.txt@@ -2,8 +2,7 @@ Harness status: OKFound 34 tests-31 Pass-3 Fail+34 PassPass Can set 'counter-increment' to CSS-wide keywords: initialPass Can set 'counter-increment' to CSS-wide keywords: inheritPass Can set 'counter-increment' to CSS-wide keywords: unset@@ -29,9 +28,9 @@ Pass Setting 'counter-increment' to an angle: calc(0rad + 0deg) throws TypeErrorPass Setting 'counter-increment' to a flexible length: 0fr throws TypeErrorPass Setting 'counter-increment' to a flexible length: 1fr throws TypeErrorPass Setting 'counter-increment' to a flexible length: -3.14fr throws TypeError-Fail Setting 'counter-increment' to a number: 0 throws TypeError-Fail Setting 'counter-increment' to a number: -3.14 throws TypeError-Fail Setting 'counter-increment' to a number: 3.14 throws TypeError+Pass Setting 'counter-increment' to a number: 0 throws TypeError+Pass Setting 'counter-increment' to a number: -3.14 throws TypeError+Pass Setting 'counter-increment' to a number: 3.14 throws TypeErrorPass Setting 'counter-increment' to a number: calc(2 + 3) throws TypeErrorPass Setting 'counter-increment' to a transform: translate(50%, 50%) throws TypeErrorPass Setting 'counter-increment' to a transform: perspective(10em) throws TypeErrordiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-reset.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-reset.txtindex e505b76b4f2..18b84835d24 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-reset.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-reset.txt@@ -2,8 +2,7 @@ Harness status: OKFound 34 tests-31 Pass-3 Fail+34 PassPass Can set 'counter-reset' to CSS-wide keywords: initialPass Can set 'counter-reset' to CSS-wide keywords: inheritPass Can set 'counter-reset' to CSS-wide keywords: unset@@ -29,9 +28,9 @@ Pass Setting 'counter-reset' to an angle: calc(0rad + 0deg) throws TypeErrorPass Setting 'counter-reset' to a flexible length: 0fr throws TypeErrorPass Setting 'counter-reset' to a flexible length: 1fr throws TypeErrorPass Setting 'counter-reset' to a flexible length: -3.14fr throws TypeError-Fail Setting 'counter-reset' to a number: 0 throws TypeError-Fail Setting 'counter-reset' to a number: -3.14 throws TypeError-Fail Setting 'counter-reset' to a number: 3.14 throws TypeError+Pass Setting 'counter-reset' to a number: 0 throws TypeError+Pass Setting 'counter-reset' to a number: -3.14 throws TypeError+Pass Setting 'counter-reset' to a number: 3.14 throws TypeErrorPass Setting 'counter-reset' to a number: calc(2 + 3) throws TypeErrorPass Setting 'counter-reset' to a transform: translate(50%, 50%) throws TypeErrorPass Setting 'counter-reset' to a transform: perspective(10em) throws TypeErrordiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-set.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-set.txtindex f5ebea9351b..ebbc5e949b0 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-set.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/counter-set.txt@@ -2,8 +2,7 @@ Harness status: OKFound 34 tests-31 Pass-3 Fail+34 PassPass Can set 'counter-set' to CSS-wide keywords: initialPass Can set 'counter-set' to CSS-wide keywords: inheritPass Can set 'counter-set' to CSS-wide keywords: unset@@ -29,9 +28,9 @@ Pass Setting 'counter-set' to an angle: calc(0rad + 0deg) throws TypeErrorPass Setting 'counter-set' to a flexible length: 0fr throws TypeErrorPass Setting 'counter-set' to a flexible length: 1fr throws TypeErrorPass Setting 'counter-set' to a flexible length: -3.14fr throws TypeError-Fail Setting 'counter-set' to a number: 0 throws TypeError-Fail Setting 'counter-set' to a number: -3.14 throws TypeError-Fail Setting 'counter-set' to a number: 3.14 throws TypeError+Pass Setting 'counter-set' to a number: 0 throws TypeError+Pass Setting 'counter-set' to a number: -3.14 throws TypeError+Pass Setting 'counter-set' to a number: 3.14 throws TypeErrorPass Setting 'counter-set' to a number: calc(2 + 3) throws TypeErrorPass Setting 'counter-set' to a transform: translate(50%, 50%) throws TypeErrorPass Setting 'counter-set' to a transform: perspective(10em) throws TypeErrordiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/cursor.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/cursor.txtindex e0c9cc3222c..77d0cbfa82c 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/cursor.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/cursor.txt@@ -2,8 +2,7 @@ Harness status: OKFound 69 tests-65 Pass-4 Fail+69 PassPass Can set 'cursor' to CSS-wide keywords: initialPass Can set 'cursor' to CSS-wide keywords: inheritPass Can set 'cursor' to CSS-wide keywords: unset@@ -64,10 +63,10 @@ Pass Setting 'cursor' to an angle: calc(0rad + 0deg) throws TypeErrorPass Setting 'cursor' to a flexible length: 0fr throws TypeErrorPass Setting 'cursor' to a flexible length: 1fr throws TypeErrorPass Setting 'cursor' to a flexible length: -3.14fr throws TypeError-Fail Setting 'cursor' to a number: 0 throws TypeError-Fail Setting 'cursor' to a number: -3.14 throws TypeError-Fail Setting 'cursor' to a number: 3.14 throws TypeError-Fail Setting 'cursor' to a number: calc(2 + 3) throws TypeError+Pass Setting 'cursor' to a number: 0 throws TypeError+Pass Setting 'cursor' to a number: -3.14 throws TypeError+Pass Setting 'cursor' to a number: 3.14 throws TypeError+Pass Setting 'cursor' to a number: calc(2 + 3) throws TypeErrorPass Setting 'cursor' to a transform: translate(50%, 50%) throws TypeErrorPass Setting 'cursor' to a transform: perspective(10em) throws TypeErrorPass Setting 'cursor' to a transform: translate3d(0px, 1px, 2px) translate(0px, 1px) rotate3d(1, 2, 3, 45deg) rotate(45deg) scale3d(1, 2, 3) scale(1, 2) skew(1deg, 1deg) skewX(1deg) skewY(45deg) perspective(1px) matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) matrix(1, 2, 3, 4, 5, 6) throws TypeErrordiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-feature-settings.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-feature-settings.txtindex 106cde34bb1..c1353afdc0a 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-feature-settings.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-feature-settings.txt@@ -2,8 +2,7 @@ Harness status: OKFound 34 tests-31 Pass-3 Fail+34 PassPass Can set 'font-feature-settings' to CSS-wide keywords: initialPass Can set 'font-feature-settings' to CSS-wide keywords: inheritPass Can set 'font-feature-settings' to CSS-wide keywords: unset@@ -29,9 +28,9 @@ Pass Setting 'font-feature-settings' to an angle: calc(0rad + 0deg) throws TypeEPass Setting 'font-feature-settings' to a flexible length: 0fr throws TypeErrorPass Setting 'font-feature-settings' to a flexible length: 1fr throws TypeErrorPass Setting 'font-feature-settings' to a flexible length: -3.14fr throws TypeError-Fail Setting 'font-feature-settings' to a number: 0 throws TypeError-Fail Setting 'font-feature-settings' to a number: -3.14 throws TypeError-Fail Setting 'font-feature-settings' to a number: 3.14 throws TypeError+Pass Setting 'font-feature-settings' to a number: 0 throws TypeError+Pass Setting 'font-feature-settings' to a number: -3.14 throws TypeError+Pass Setting 'font-feature-settings' to a number: 3.14 throws TypeErrorPass Setting 'font-feature-settings' to a number: calc(2 + 3) throws TypeErrorPass Setting 'font-feature-settings' to a transform: translate(50%, 50%) throws TypeErrorPass Setting 'font-feature-settings' to a transform: perspective(10em) throws TypeErrordiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variation-settings.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variation-settings.txtindex ad0b97c5f1e..8944e3371dc 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variation-settings.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variation-settings.txt@@ -2,8 +2,7 @@ Harness status: OKFound 33 tests-29 Pass-4 Fail+33 PassPass Can set 'font-variation-settings' to CSS-wide keywords: initialPass Can set 'font-variation-settings' to CSS-wide keywords: inheritPass Can set 'font-variation-settings' to CSS-wide keywords: unset@@ -29,10 +28,10 @@ Pass Setting 'font-variation-settings' to an angle: calc(0rad + 0deg) throws TypPass Setting 'font-variation-settings' to a flexible length: 0fr throws TypeErrorPass Setting 'font-variation-settings' to a flexible length: 1fr throws TypeErrorPass Setting 'font-variation-settings' to a flexible length: -3.14fr throws TypeError-Fail Setting 'font-variation-settings' to a number: 0 throws TypeError-Fail Setting 'font-variation-settings' to a number: -3.14 throws TypeError-Fail Setting 'font-variation-settings' to a number: 3.14 throws TypeError-Fail Setting 'font-variation-settings' to a number: calc(2 + 3) throws TypeError+Pass Setting 'font-variation-settings' to a number: 0 throws TypeError+Pass Setting 'font-variation-settings' to a number: -3.14 throws TypeError+Pass Setting 'font-variation-settings' to a number: 3.14 throws TypeError+Pass Setting 'font-variation-settings' to a number: calc(2 + 3) throws TypeErrorPass Setting 'font-variation-settings' to a transform: translate(50%, 50%) throws TypeErrorPass Setting 'font-variation-settings' to a transform: perspective(10em) throws TypeErrorPass Setting 'font-variation-settings' to a transform: translate3d(0px, 1px, 2px) translate(0px, 1px) rotate3d(1, 2, 3, 45deg) rotate(45deg) scale3d(1, 2, 3) scale(1, 2) skew(1deg, 1deg) skewX(1deg) skewY(45deg) perspective(1px) matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) matrix(1, 2, 3, 4, 5, 6) throws TypeError