mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-12 20:11:51 +00:00
LibWeb: Validate operator count when parsing a calculation
Previously, we would allow calc values such as `calc(min(1 2))`, which would be simplified to `calc(3)` because we assumed that numbers not separated by an operator represented a sum. We now validate that the number of operators we see is as we would expect before collecting these values into a sum node.
This commit is contained in:
parent
43778e9493
commit
78b6032940
Notes:
github-actions[bot]
2025-07-02 09:14:07 +00:00
Author: https://github.com/tcl3
Commit: 78b6032940
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5243
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/konradekk
14 changed files with 646 additions and 12 deletions
|
@ -4050,7 +4050,19 @@ RefPtr<CalculationNode const> Parser::parse_a_calculation(Vector<ComponentValue>
|
|||
}
|
||||
// Otherwise, replace values with a Sum node containing the value items of values as its children.
|
||||
if (!single_value.has_value()) {
|
||||
values.remove_all_matching([](CalcParsing::Node& value) { return value.has<CalcParsing::Operator>(); });
|
||||
auto operator_count = 0u;
|
||||
for (size_t i = 0; i < values.size();) {
|
||||
auto& value = values[i];
|
||||
if (value.has<CalcParsing::Operator>()) {
|
||||
operator_count++;
|
||||
values.remove(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (values.size() == 0 || operator_count != values.size() - 1)
|
||||
return nullptr;
|
||||
|
||||
single_value = make<CalcParsing::SumNode>(move(values));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue