1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00

LibWeb: Reject invalid tokens in calc() expressions

If we finish parsing a calculation tree and it still contains
UnparsedCalculationNodes, then it's not valid, and we shouldn't create
a StyleValue from it.
This commit is contained in:
Sam Atkins 2023-05-23 13:52:58 +01:00 committed by Andreas Kling
parent fa25f70086
commit 4e47e6a3d6

View file

@ -7591,6 +7591,7 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calculation(Vector<ComponentVal
return {};
}
node = leaf_calculation.release_nonnull();
return {};
}
// 2. If leaf is a math function, replace leaf with the internal representation of that math function.
@ -7604,6 +7605,7 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calculation(Vector<ComponentVal
return {};
}
node = leaf_calculation.release_nonnull();
return {};
} else {
// FIXME: Parse more math functions once we have them.
parsing_failed_for_child_node = true;
@ -7611,6 +7613,10 @@ ErrorOr<OwnPtr<CalculationNode>> Parser::parse_a_calculation(Vector<ComponentVal
}
}
// NOTE: If we get here, then we have an UnparsedCalculationNode that didn't get replaced with something else.
// So, the calc() is invalid.
dbgln_if(CSS_PARSER_DEBUG, "Leftover UnparsedCalculationNode in calc tree! That probably means the syntax is invalid, but maybe we just didn't implement `{}` yet.", component_value.to_debug_string());
parsing_failed_for_child_node = true;
return {};
}));