diff --git a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp index 6e43b1a79f3..3481da4daa2 100644 --- a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp @@ -2045,12 +2045,19 @@ RefPtr Parser::parse_stroke_dasharray_value(TokenStream is a list of comma and/or white space separated or values. A value represents a value in user units. auto value = parse_number_value(tokens); + if (value && value->is_number() && value->as_number().value() < 0) + return {}; + if (value) { dashes.append(value.release_nonnull()); } else { auto value = parse_length_percentage_value(tokens); if (!value) return {}; + if (value->is_percentage() && value->as_percentage().value() < 0) + return {}; + if (value->is_length() && value->as_length().length().raw_value() < 0) + return {}; dashes.append(value.release_nonnull()); } diff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/painting/parsing/stroke-dasharray-invalid.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/painting/parsing/stroke-dasharray-invalid.txt new file mode 100644 index 00000000000..f736e63f191 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/svg/painting/parsing/stroke-dasharray-invalid.txt @@ -0,0 +1,12 @@ +Harness status: OK + +Found 7 tests + +7 Pass +Pass e.style['stroke-dasharray'] = "auto" should not set the property value +Pass e.style['stroke-dasharray'] = "none 10px" should not set the property value +Pass e.style['stroke-dasharray'] = "20px / 30px" should not set the property value +Pass e.style['stroke-dasharray'] = "-40px" should not set the property value +Pass e.style['stroke-dasharray'] = "calc(2px + 3)" should not set the property value +Pass e.style['stroke-dasharray'] = "calc(10% + 5)" should not set the property value +Pass e.style['stroke-dasharray'] = "calc(40 + calc(3px + 6%))" should not set the property value \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/painting/parsing/stroke-dasharray-invalid.svg b/Tests/LibWeb/Text/input/wpt-import/svg/painting/parsing/stroke-dasharray-invalid.svg new file mode 100644 index 00000000000..b25c43a95fd --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/svg/painting/parsing/stroke-dasharray-invalid.svg @@ -0,0 +1,25 @@ + + + SVG Painting: parsing stroke-dasharray with invalid values + + + + + + + + + +