LibWeb: Don't assume calc() simplification worked on invalid tree

Fixes #4469
This commit is contained in:
Andreas Kling 2025-04-25 15:00:02 +02:00 committed by Jelle Raaijmakers
commit d8ea16d94e
Notes: github-actions[bot] 2025-04-25 14:56:08 +00:00
3 changed files with 123 additions and 2 deletions

View file

@ -2926,8 +2926,9 @@ NonnullRefPtr<CalculationNode const> simplify_a_calculation_tree(CalculationNode
// running roots operation using its children, expressed in the results canonical unit.
if (root->is_math_function_node()) {
if (auto maybe_simplified = root->run_operation_if_possible(context, resolution_context); maybe_simplified.has_value()) {
// NOTE: If this returns nullptr, that's a logic error in the code, so it's fine to assert that it's nonnull.
return make_calculation_node(maybe_simplified.release_value(), context).release_nonnull();
if (auto node = make_calculation_node(maybe_simplified.release_value(), context))
return node.release_nonnull();
return root;
}
}

View file

@ -0,0 +1,54 @@
Harness status: OK
Found 48 tests
46 Pass
2 Fail
Pass e.style['border-left-width'] = "min()" should not set the property value
Pass e.style['border-left-width'] = "min( )" should not set the property value
Pass e.style['border-left-width'] = "min(,)" should not set the property value
Pass e.style['border-left-width'] = "min(1py)" should not set the property value
Pass e.style['border-left-width'] = "min(1px, )" should not set the property value
Pass e.style['border-left-width'] = "min(, 1px)" should not set the property value
Pass e.style['border-left-width'] = "min(1px + )" should not set the property value
Pass e.style['border-left-width'] = "min(1px - )" should not set the property value
Pass e.style['border-left-width'] = "min(1px * )" should not set the property value
Pass e.style['border-left-width'] = "min(1px / )" should not set the property value
Fail e.style['border-left-width'] = "min(1px 2px)" should not set the property value
Pass e.style['border-left-width'] = "min(1px, , 2px)" should not set the property value
Pass e.style['border-left-width'] = "max()" should not set the property value
Pass e.style['border-left-width'] = "max( )" should not set the property value
Pass e.style['border-left-width'] = "max(,)" should not set the property value
Pass e.style['border-left-width'] = "max(1py)" should not set the property value
Pass e.style['border-left-width'] = "max(1px, )" should not set the property value
Pass e.style['border-left-width'] = "max(, 1px)" should not set the property value
Pass e.style['border-left-width'] = "max(1px + )" should not set the property value
Pass e.style['border-left-width'] = "max(1px - )" should not set the property value
Pass e.style['border-left-width'] = "max(1px * )" should not set the property value
Pass e.style['border-left-width'] = "max(1px / )" should not set the property value
Fail e.style['border-left-width'] = "max(1px 2px)" should not set the property value
Pass e.style['border-left-width'] = "max(1px, , 2px)" should not set the property value
Pass e.style['border-left-width'] = "min(0)" should not set the property value
Pass e.style['border-left-width'] = "min(0%)" should not set the property value
Pass e.style['border-left-width'] = "min(0s)" should not set the property value
Pass e.style['border-left-width'] = "min(0Hz)" should not set the property value
Pass e.style['border-left-width'] = "min(0dpi)" should not set the property value
Pass e.style['border-left-width'] = "min(0fr)" should not set the property value
Pass e.style['border-left-width'] = "min(1px, 0)" should not set the property value
Pass e.style['border-left-width'] = "min(1px, 0%)" should not set the property value
Pass e.style['border-left-width'] = "min(1px, 0s)" should not set the property value
Pass e.style['border-left-width'] = "min(1px, 0Hz)" should not set the property value
Pass e.style['border-left-width'] = "min(1px, 0dpi)" should not set the property value
Pass e.style['border-left-width'] = "min(1px, 0fr)" should not set the property value
Pass e.style['border-left-width'] = "max(0)" should not set the property value
Pass e.style['border-left-width'] = "max(0%)" should not set the property value
Pass e.style['border-left-width'] = "max(0s)" should not set the property value
Pass e.style['border-left-width'] = "max(0Hz)" should not set the property value
Pass e.style['border-left-width'] = "max(0dpi)" should not set the property value
Pass e.style['border-left-width'] = "max(0fr)" should not set the property value
Pass e.style['border-left-width'] = "max(1px, 0)" should not set the property value
Pass e.style['border-left-width'] = "max(1px, 0%)" should not set the property value
Pass e.style['border-left-width'] = "max(1px, 0s)" should not set the property value
Pass e.style['border-left-width'] = "max(1px, 0Hz)" should not set the property value
Pass e.style['border-left-width'] = "max(1px, 0dpi)" should not set the property value
Pass e.style['border-left-width'] = "max(1px, 0fr)" should not set the property value

View file

@ -0,0 +1,66 @@
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-values-4/#comp-func">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#lengths">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-type-checking">
<link rel="author" title="Xiaocheng Hu" href="mailto:xiaochengh@chromium.org">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../support/parsing-testcommon.js"></script>
<script>
function test_invalid_length(value) {
// 'border-width' accepts <length> only, not <percentage> or any mixes.
test_invalid_value('border-left-width', value);
}
// Syntax checking
test_invalid_length('min()');
test_invalid_length('min( )');
test_invalid_length('min(,)');
test_invalid_length('min(1py)');
test_invalid_length('min(1px, )');
test_invalid_length('min(, 1px)');
test_invalid_length('min(1px + )');
test_invalid_length('min(1px - )');
test_invalid_length('min(1px * )');
test_invalid_length('min(1px / )');
test_invalid_length('min(1px 2px)');
test_invalid_length('min(1px, , 2px)');
test_invalid_length('max()');
test_invalid_length('max( )');
test_invalid_length('max(,)');
test_invalid_length('max(1py)');
test_invalid_length('max(1px, )');
test_invalid_length('max(, 1px)');
test_invalid_length('max(1px + )');
test_invalid_length('max(1px - )');
test_invalid_length('max(1px * )');
test_invalid_length('max(1px / )');
test_invalid_length('max(1px 2px)');
test_invalid_length('max(1px, , 2px)');
// Type checking
test_invalid_length('min(0)');
test_invalid_length('min(0%)');
test_invalid_length('min(0s)');
test_invalid_length('min(0Hz)');
test_invalid_length('min(0dpi)');
test_invalid_length('min(0fr)');
test_invalid_length('min(1px, 0)');
test_invalid_length('min(1px, 0%)');
test_invalid_length('min(1px, 0s)');
test_invalid_length('min(1px, 0Hz)');
test_invalid_length('min(1px, 0dpi)');
test_invalid_length('min(1px, 0fr)');
test_invalid_length('max(0)');
test_invalid_length('max(0%)');
test_invalid_length('max(0s)');
test_invalid_length('max(0Hz)');
test_invalid_length('max(0dpi)');
test_invalid_length('max(0fr)');
test_invalid_length('max(1px, 0)');
test_invalid_length('max(1px, 0%)');
test_invalid_length('max(1px, 0s)');
test_invalid_length('max(1px, 0Hz)');
test_invalid_length('max(1px, 0dpi)');
test_invalid_length('max(1px, 0fr)');
</script>