mirror of
https://github.com/servo/servo.git
synced 2025-08-09 15:35:34 +01:00
style: Properly reject numbers as part of <length-percentage>.
We never fast-reject numbers (because they could be part of a product). Without this refactoring we'd accept stuff like calc(10) and crash during the evaluation for obvious reasons. Differential Revision: https://phabricator.services.mozilla.com/D63401
This commit is contained in:
parent
039ef3dd53
commit
787ac98d18
3 changed files with 62 additions and 19 deletions
|
@ -446,13 +446,26 @@ impl CalcNode {
|
|||
Ok(node)
|
||||
}
|
||||
|
||||
/// Tries to simplify this expression into a `<length>` or `<percentage`>
|
||||
/// Tries to simplify this expression into a `<length>` or `<percentage>`
|
||||
/// value.
|
||||
fn into_length_or_percentage(
|
||||
mut self,
|
||||
clamping_mode: AllowedNumericType,
|
||||
) -> Result<CalcLengthPercentage, ()> {
|
||||
self.simplify_and_sort_children();
|
||||
// Keep track of whether there's any invalid member of the calculation,
|
||||
// so as to reject the calculation properly at parse-time.
|
||||
let mut any_invalid = false;
|
||||
self.visit_depth_first(|node| {
|
||||
if let CalcNode::Leaf(ref l) = *node {
|
||||
any_invalid |= !matches!(*l, Leaf::Percentage(..) | Leaf::Length(..));
|
||||
}
|
||||
node.simplify_and_sort_direct_children();
|
||||
});
|
||||
|
||||
if any_invalid {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
Ok(CalcLengthPercentage {
|
||||
clamping_mode,
|
||||
node: self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue