From 18cccd76334025b47aae7bb20f7960944743b3ca Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 12 Mar 2025 13:57:10 +0000 Subject: [PATCH] LibWeb/CSS: Don't allow negative values in `border-radius` property --- .../LibWeb/CSS/Parser/PropertyParsing.cpp | 4 +++ Libraries/LibWeb/CSS/Properties.json | 4 +++ .../parsing/border-radius-invalid.txt | 16 ++++++++++ .../parsing/border-radius-invalid.html | 29 +++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/border-radius-invalid.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/border-radius-invalid.html diff --git a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp index 9ee58e236ba..7b49c242df8 100644 --- a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp @@ -1659,6 +1659,10 @@ RefPtr Parser::parse_border_radius_shorthand_value(TokenStreamis_length() && !property_accepts_length(PropertyID::BorderRadius, maybe_dimension->length())) + return nullptr; + if (maybe_dimension->is_percentage() && !property_accepts_percentage(PropertyID::BorderRadius, maybe_dimension->percentage())) + return nullptr; if (reading_vertical) { vertical_radii.append(maybe_dimension.release_value()); } else { diff --git a/Libraries/LibWeb/CSS/Properties.json b/Libraries/LibWeb/CSS/Properties.json index 58257369d3b..f2e6de3fdde 100644 --- a/Libraries/LibWeb/CSS/Properties.json +++ b/Libraries/LibWeb/CSS/Properties.json @@ -615,6 +615,10 @@ "border-bottom-left-radius", "border-bottom-right-radius" ], + "valid-types": [ + "length [0,∞]", + "percentage [0,∞]" + ], "percentages-resolve-to": "length" }, "border-right": { diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/border-radius-invalid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/border-radius-invalid.txt new file mode 100644 index 00000000000..f92d4293e1d --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/border-radius-invalid.txt @@ -0,0 +1,16 @@ +Harness status: OK + +Found 11 tests + +11 Pass +Pass e.style['border-radius'] = "auto" should not set the property value +Pass e.style['border-radius'] = "none" should not set the property value +Pass e.style['border-radius'] = "1px 2px 3px 4px 5px" should not set the property value +Pass e.style['border-radius'] = "-1px" should not set the property value +Pass e.style['border-radius'] = "1px -2px" should not set the property value +Pass e.style['border-radius'] = "1em /" should not set the property value +Pass e.style['border-radius'] = "1px / 2px / 3px" should not set the property value +Pass e.style['border-radius'] = "4 / 5" should not set the property value +Pass e.style['border-radius'] = "5em 1px 5em 2% 5em 3px 5em 4%" should not set the property value +Pass e.style['border-radius'] = "1px 5em 2% 5em 3px 5em 4% 5em" should not set the property value +Pass e.style['border-top-left-radius'] = "10px 20px 30px" should not set the property value \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/border-radius-invalid.html b/Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/border-radius-invalid.html new file mode 100644 index 00000000000..f4f31cdfed1 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/border-radius-invalid.html @@ -0,0 +1,29 @@ + + + + +CSS Backgrounds and Borders Module Level 3: parsing border-radius with invalid values + + + + + + + + + +