diff --git a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp index 9f2eb7e20c8..360449f82b2 100644 --- a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp @@ -214,71 +214,108 @@ Optional Parser::parse_css_value_for_properties(Readon // / come before , so that 0 is not interpreted as a in case both are allowed. if (auto property = any_property_accepts_type(property_ids, ValueType::Integer); property.has_value()) { auto context_guard = push_temporary_value_parsing_context(*property); + auto transaction = tokens.begin_transaction(); if (auto value = parse_integer_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_integer() && property_accepts_integer(*property, value->as_integer().integer())) + } + if (value->is_integer() && property_accepts_integer(*property, value->as_integer().integer())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto property = any_property_accepts_type(property_ids, ValueType::Number); property.has_value()) { auto context_guard = push_temporary_value_parsing_context(*property); + auto transaction = tokens.begin_transaction(); if (auto value = parse_number_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_number() && property_accepts_number(*property, value->as_number().number())) + } + if (value->is_number() && property_accepts_number(*property, value->as_number().number())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto property = any_property_accepts_type(property_ids, ValueType::Angle); property.has_value()) { auto context_guard = push_temporary_value_parsing_context(*property); + auto transaction = tokens.begin_transaction(); if (property_accepts_type(*property, ValueType::Percentage)) { if (auto value = parse_angle_percentage_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_angle() && property_accepts_angle(*property, value->as_angle().angle())) + } + if (value->is_angle() && property_accepts_angle(*property, value->as_angle().angle())) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) + } + if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto value = parse_angle_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_angle() && property_accepts_angle(*property, value->as_angle().angle())) + } + if (value->is_angle() && property_accepts_angle(*property, value->as_angle().angle())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto property = any_property_accepts_type(property_ids, ValueType::Flex); property.has_value()) { auto context_guard = push_temporary_value_parsing_context(*property); + auto transaction = tokens.begin_transaction(); if (auto value = parse_flex_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_flex() && property_accepts_flex(*property, value->as_flex().flex())) + } + if (value->is_flex() && property_accepts_flex(*property, value->as_flex().flex())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto property = any_property_accepts_type(property_ids, ValueType::Frequency); property.has_value()) { auto context_guard = push_temporary_value_parsing_context(*property); + auto transaction = tokens.begin_transaction(); if (property_accepts_type(*property, ValueType::Percentage)) { if (auto value = parse_frequency_percentage_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_frequency() && property_accepts_frequency(*property, value->as_frequency().frequency())) + } + if (value->is_frequency() && property_accepts_frequency(*property, value->as_frequency().frequency())) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) + } + if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto value = parse_frequency_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_frequency() && property_accepts_frequency(*property, value->as_frequency().frequency())) + } + if (value->is_frequency() && property_accepts_frequency(*property, value->as_frequency().frequency())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } @@ -290,62 +327,94 @@ Optional Parser::parse_css_value_for_properties(Readon if (auto property = any_property_accepts_type(property_ids, ValueType::Length); property.has_value()) { auto context_guard = push_temporary_value_parsing_context(*property); + auto transaction = tokens.begin_transaction(); if (property_accepts_type(*property, ValueType::Percentage)) { if (auto value = parse_length_percentage_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_length() && property_accepts_length(*property, value->as_length().length())) + } + if (value->is_length() && property_accepts_length(*property, value->as_length().length())) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) + } + if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto value = parse_length_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_length() && property_accepts_length(*property, value->as_length().length())) + } + if (value->is_length() && property_accepts_length(*property, value->as_length().length())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto property = any_property_accepts_type(property_ids, ValueType::Resolution); property.has_value()) { auto context_guard = push_temporary_value_parsing_context(*property); + auto transaction = tokens.begin_transaction(); if (auto value = parse_resolution_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_resolution() && property_accepts_resolution(*property, value->as_resolution().resolution())) + } + if (value->is_resolution() && property_accepts_resolution(*property, value->as_resolution().resolution())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto property = any_property_accepts_type(property_ids, ValueType::Time); property.has_value()) { auto context_guard = push_temporary_value_parsing_context(*property); + auto transaction = tokens.begin_transaction(); if (property_accepts_type(*property, ValueType::Percentage)) { if (auto value = parse_time_percentage_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_time() && property_accepts_time(*property, value->as_time().time())) + } + if (value->is_time() && property_accepts_time(*property, value->as_time().time())) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) + } + if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } if (auto value = parse_time_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_time() && property_accepts_time(*property, value->as_time().time())) + } + if (value->is_time() && property_accepts_time(*property, value->as_time().time())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } // is checked after the types. if (auto property = any_property_accepts_type(property_ids, ValueType::Percentage); property.has_value()) { auto context_guard = push_temporary_value_parsing_context(*property); + auto transaction = tokens.begin_transaction(); if (auto value = parse_percentage_value(tokens)) { - if (value->is_calculated()) + if (value->is_calculated()) { + transaction.commit(); return PropertyAndValue { *property, value }; - if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) + } + if (value->is_percentage() && property_accepts_percentage(*property, value->as_percentage().percentage())) { + transaction.commit(); return PropertyAndValue { *property, value }; + } } } diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-parsing-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-parsing-001.txt index 6ac31894b3f..999ac3b54e7 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-parsing-001.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-parsing-001.txt @@ -2,8 +2,7 @@ Harness status: OK Found 26 tests -25 Pass -1 Fail +26 Pass Pass Default gap is 'normal' Pass gap accepts pixels Pass gap accepts pixels 2 @@ -29,4 +28,4 @@ Pass Resolution gap is invalid Pass Time gap is invalid Pass gap with three values is invalid Pass gap with slash is invalid -Fail gap with one wrong value is invalid \ No newline at end of file +Pass gap with one wrong value is invalid \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/grid-gap-parsing-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/grid-gap-parsing-001.txt index 9f987f0ca68..cf4b0dfaad4 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/grid-gap-parsing-001.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/grid-gap-parsing-001.txt @@ -2,8 +2,7 @@ Harness status: OK Found 26 tests -25 Pass -1 Fail +26 Pass Pass Default grid-gap is 'normal' Pass grid-gap accepts pixels Pass grid-gap accepts pixels 2 @@ -29,4 +28,4 @@ Pass Resolution grid-gap is invalid Pass Time grid-gap is invalid Pass grid-gap with three values is invalid Pass grid-gap with slash is invalid -Fail grid-gap with one wrong value is invalid \ No newline at end of file +Pass grid-gap with one wrong value is invalid \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/parsing/grid-gap-invalid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/parsing/grid-gap-invalid.txt new file mode 100644 index 00000000000..971ac28ba9e --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/parsing/grid-gap-invalid.txt @@ -0,0 +1,9 @@ +Harness status: OK + +Found 4 tests + +4 Pass +Pass e.style['grid-gap'] = "auto" should not set the property value +Pass e.style['grid-gap'] = "-10px" should not set the property value +Pass e.style['grid-gap'] = "10px 20% 30px" should not set the property value +Pass e.style['grid-gap'] = "normal 10px normal" should not set the property value \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/background-size-invalid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/background-size-invalid.txt new file mode 100644 index 00000000000..4ba6f7ae946 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/parsing/background-size-invalid.txt @@ -0,0 +1,8 @@ +Harness status: OK + +Found 3 tests + +3 Pass +Pass e.style['background-size'] = "-1px" should not set the property value +Pass e.style['background-size'] = "2% -3%" should not set the property value +Pass e.style['background-size'] = "1px 2px 3px" should not set the property value \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/parsing/columns-invalid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/parsing/columns-invalid.txt new file mode 100644 index 00000000000..c3e2cad2c7d --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/parsing/columns-invalid.txt @@ -0,0 +1,14 @@ +Harness status: OK + +Found 9 tests + +9 Pass +Pass e.style['columns'] = "none" should not set the property value +Pass e.style['columns'] = "10px 20px" should not set the property value +Pass e.style['columns'] = "10 20" should not set the property value +Pass e.style['columns'] = "0 0" should not set the property value +Pass e.style['columns'] = "0 7px" should not set the property value +Pass e.style['columns'] = "auto auto auto" should not set the property value +Pass e.style['columns'] = "10em auto auto" should not set the property value +Pass e.style['columns'] = "initial initial" should not set the property value +Pass e.style['columns'] = "inherit inherit" should not set the property value \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/parsing/columns-valid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/parsing/columns-valid.txt new file mode 100644 index 00000000000..ef8162b63ef --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/parsing/columns-valid.txt @@ -0,0 +1,20 @@ +Harness status: OK + +Found 15 tests + +15 Pass +Pass e.style['columns'] = "auto 3" should set the property value +Pass e.style['columns'] = "auto 10em" should set the property value +Pass e.style['columns'] = "3 auto" should set the property value +Pass e.style['columns'] = "10em auto" should set the property value +Pass e.style['columns'] = "2 10px" should set the property value +Pass e.style['columns'] = "10px 2" should set the property value +Pass e.style['columns'] = "auto" should set the property value +Pass e.style['columns'] = "auto auto" should set the property value +Pass e.style['columns'] = "7" should set the property value +Pass e.style['columns'] = "7em" should set the property value +Pass e.style['columns'] = "0 1" should set the property value +Pass e.style['columns'] = "1 0" should set the property value +Pass e.style['columns'] = "0px 1" should set the property value +Pass e.style['columns'] = "initial" should set the property value +Pass e.style['columns'] = "inherit" should set the property value \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-align/parsing/grid-gap-invalid.html b/Tests/LibWeb/Text/input/wpt-import/css/css-align/parsing/grid-gap-invalid.html new file mode 100644 index 00000000000..972b4b6f0b6 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-align/parsing/grid-gap-invalid.html @@ -0,0 +1,22 @@ + + + + +CSS Box Alignment Level 3: parsing grid-gap with invalid values + + + + + + + + + + + diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/background-size-invalid.html b/Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/background-size-invalid.html new file mode 100644 index 00000000000..bfecf199b4b --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-backgrounds/parsing/background-size-invalid.html @@ -0,0 +1,22 @@ + + + + +CSS Backgrounds and Borders Module Level 3: parsing background-size with invalid values + + + + + + + + + + + diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-multicol/parsing/columns-invalid.html b/Tests/LibWeb/Text/input/wpt-import/css/css-multicol/parsing/columns-invalid.html new file mode 100644 index 00000000000..d50a2713cf7 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-multicol/parsing/columns-invalid.html @@ -0,0 +1,32 @@ + + + + +CSS Multi-column Layout: parsing columns with invalid values + + + + + + + + + + diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-multicol/parsing/columns-valid.html b/Tests/LibWeb/Text/input/wpt-import/css/css-multicol/parsing/columns-valid.html new file mode 100644 index 00000000000..ba42cf0e205 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-multicol/parsing/columns-valid.html @@ -0,0 +1,35 @@ + + + + +CSS Multi-column Layout: parsing columns with valid values + + + + + + + + + +