From 632fc73643c5edc9c1bcb16f7487117463220781 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 12 Mar 2025 13:51:19 +0000 Subject: [PATCH] LibWeb/CSS: Don't allow negative border radius in `box-shadow` property --- .../LibWeb/CSS/Parser/PropertyParsing.cpp | 4 ++ .../parsing/box-shadow-invalid.txt | 45 +++++++++++++ .../parsing/box-shadow-invalid.html | 66 +++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/box-shadow-invalid.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/box-shadow-invalid.html diff --git a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp index 00cebe37399..9ee58e236ba 100644 --- a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp @@ -1816,6 +1816,10 @@ RefPtr Parser::parse_single_shadow_value(TokenStreamis_length() && blur_radius->as_length().length().raw_value() < 0) + return nullptr; + if (blur_radius->is_percentage() && blur_radius->as_percentage().value() < 0) + return nullptr; tokens.discard_a_token(); // spread distance (optional) diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/box-shadow-invalid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/box-shadow-invalid.txt new file mode 100644 index 00000000000..b2083ed2b53 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/box-shadow-invalid.txt @@ -0,0 +1,45 @@ +Harness status: OK + +Found 40 tests + +40 Pass +Pass e.style['box-shadow'] = "auto" should not set the property value +Pass e.style['box-shadow'] = "1 2" should not set the property value +Pass e.style['box-shadow'] = "1% 2%" should not set the property value +Pass e.style['box-shadow'] = "1px calc(2px + 2%)" should not set the property value +Pass e.style['box-shadow'] = "1px" should not set the property value +Pass e.style['box-shadow'] = "1px 2px 3px 4px 5px" should not set the property value +Pass e.style['box-shadow'] = "red 1px 2px blue" should not set the property value +Pass e.style['box-shadow'] = "red" should not set the property value +Pass e.style['box-shadow'] = "4px red" should not set the property value +Pass e.style['box-shadow'] = "red 4px" should not set the property value +Pass e.style['box-shadow'] = "-4px red 4px" should not set the property value +Pass e.style['box-shadow'] = "red -4px 4px red" should not set the property value +Pass e.style['box-shadow'] = "-4px 4px red 0" should not set the property value +Pass e.style['box-shadow'] = "-4px 4px 0 red 0" should not set the property value +Pass e.style['box-shadow'] = "inset" should not set the property value +Pass e.style['box-shadow'] = "inset 4px" should not set the property value +Pass e.style['box-shadow'] = "4px inset" should not set the property value +Pass e.style['box-shadow'] = "4px inset -4px" should not set the property value +Pass e.style['box-shadow'] = "inset 4px -4px inset" should not set the property value +Pass e.style['box-shadow'] = "4px -4px inset 0" should not set the property value +Pass e.style['box-shadow'] = "4px -4px 0 inset 0" should not set the property value +Pass e.style['box-shadow'] = "red inset" should not set the property value +Pass e.style['box-shadow'] = "inset red" should not set the property value +Pass e.style['box-shadow'] = "4px red inset" should not set the property value +Pass e.style['box-shadow'] = "red inset 4px" should not set the property value +Pass e.style['box-shadow'] = "4px inset red" should not set the property value +Pass e.style['box-shadow'] = "inset red 4px" should not set the property value +Pass e.style['box-shadow'] = "4px red inset -4px" should not set the property value +Pass e.style['box-shadow'] = "4px inset red -4px" should not set the property value +Pass e.style['box-shadow'] = "inset 4px red -4px" should not set the property value +Pass e.style['box-shadow'] = "4px red 4px inset" should not set the property value +Pass e.style['box-shadow'] = "red 4px inset -4px" should not set the property value +Pass e.style['box-shadow'] = "4px inset -4px red" should not set the property value +Pass e.style['box-shadow'] = "4px -4px red inset 0" should not set the property value +Pass e.style['box-shadow'] = "4px -4px inset red 0" should not set the property value +Pass e.style['box-shadow'] = "inset 4px -4px red 0" should not set the property value +Pass e.style['box-shadow'] = "4px -4px red 0 inset" should not set the property value +Pass e.style['box-shadow'] = "red 4px -4px inset 0" should not set the property value +Pass e.style['box-shadow'] = "4px -4px inset 0 red" should not set the property value +Pass e.style['box-shadow'] = "1px 1px -1px" 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/box-shadow-invalid.html b/Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/box-shadow-invalid.html new file mode 100644 index 00000000000..c3040184fcd --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/box-shadow-invalid.html @@ -0,0 +1,66 @@ + + + + +CSS Backgrounds and Borders Module Level 3: parsing box-shadow with invalid values + + + + + + + + + + + + + +