diff --git a/src/value/operator.rs b/src/value/operator.rs index 3d38eb111..1f3406846 100644 --- a/src/value/operator.rs +++ b/src/value/operator.rs @@ -1,5 +1,6 @@ use crate::css::{CssString, Value}; use crate::value::{ListSeparator, Numeric, Quotes}; +use num_traits::Zero; use std::fmt; /// An operator that can be used in a sass value. @@ -140,10 +141,10 @@ impl Operator { Operator::Div if a.is_calculated() || b.is_calculated() => { match (a, b) { (Value::Color(a, _), Value::Numeric(b, _)) - if b.is_no_unit() => + if b.is_no_unit() && !b.value.is_zero() => { - let bn = b.as_ratio().ok()?; - Some((a.to_rgba().as_ref() / bn).into()) + let bn = dbg!(b).as_ratio().ok()?; + Some((dbg!(a).to_rgba().as_ref() / bn).into()) } (Value::Numeric(ref a, _), Value::Numeric(ref b, _)) => { Some((a / b).into()) diff --git a/tests/basic_manual.rs b/tests/basic_manual.rs index bcfa9fdc1..427b7b94c 100644 --- a/tests/basic_manual.rs +++ b/tests/basic_manual.rs @@ -384,6 +384,25 @@ fn issue_116() { ); } +/// https://github.com/kaj/rsass/issues/122 +/// A division by zero that causes a panic +mod issue_122 { + use super::check_value; + // Note: The important thing here is not to panic, the exact + // output may be changed in the future, maybe to report an error. + #[test] + fn reduced() { + check_value("(#111 + #aaa)/0", "#bbbbbb/0") + } + #[test] + fn reported() { + check_value( + "54A444/0+-4444M4#444/-4444/0+-4444M4#444+44/0+444/0+.44444O#444+44/0+4/46", + "InfinityA444-4444M4 black/0-4444M4 #444InfinityInfinity0.44444O #444Infinity0.0869565217", + ) + } +} + /// Test auto-converted from "sass-spec/spec/libsass/rel.hrx", except one failing unit calculation. #[test] fn rel() {