Skip to content

Commit

Permalink
Fix crash in invalid calc
Browse files Browse the repository at this point in the history
Fixes #626
  • Loading branch information
devongovett committed Nov 3, 2024
1 parent e3c8e12 commit 378955e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7868,6 +7868,10 @@ mod tests {
".foo { width: calc(100% - clamp(1.125rem, 1.25vw, 1.2375rem) - clamp(1.125rem, 1.25vw, 1.2375rem)); }",
".foo{width:calc(100% - clamp(1.125rem,1.25vw,1.2375rem) - clamp(1.125rem,1.25vw,1.2375rem))}",
);
minify_test(
".foo { width: calc(100% - 2 (2 * var(--card-margin))); }",
".foo{width:calc(100% - 2 (2*var(--card-margin)))}",
);
}

#[test]
Expand Down
10 changes: 6 additions & 4 deletions src/values/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,12 +926,14 @@ impl<V: AddInternal + std::convert::Into<Calc<V>> + std::convert::From<Calc<V>>
Calc::Sum(Box::new(Calc::Number(a)), Box::new(Calc::Sum(b, c)))
}
}
(a @ Calc::Product(..), b) => Calc::Sum(Box::new(a), Box::new(b)),
(a, b @ Calc::Product(..)) => Calc::Sum(Box::new(a), Box::new(b)),
(Calc::Value(a), b) => (a.add(V::from(b))).into(),
(a, Calc::Value(b)) => (V::from(a).add(*b)).into(),
(a @ Calc::Number(_), b)
| (a, b @ Calc::Number(_))
| (a @ Calc::Product(..), b)
| (a, b @ Calc::Product(..)) => Calc::Sum(Box::new(a), Box::new(b)),
(Calc::Function(a), b) => Calc::Sum(Box::new(Calc::Function(a)), Box::new(b)),
(a, Calc::Function(b)) => Calc::Sum(Box::new(a), Box::new(Calc::Function(b))),
(Calc::Value(a), b) => (a.add(V::from(b))).into(),
(a, Calc::Value(b)) => (V::from(a).add(*b)).into(),
(a @ Calc::Sum(..), b @ Calc::Sum(..)) => V::from(a).add(V::from(b)).into(),
}
}
Expand Down

0 comments on commit 378955e

Please sign in to comment.