Repository: clarkmcc/cel-rust (language: rust)

Issue:
v0.7.0: Expression `size == "50"` causes a panic. 
I would expect that no expression can panic the interpreter. 

```
unable to compare String("50") with Function("size", None)
thread 'limit::tests::cel::size_function_and_size_var' panicked at /Users/chirino/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cel-interpreter-0.7.0/src/objects.rs:270:23:
unable to compare String("50") with Function("size", None)
```


Discussion / hints:

Fix patch:
diff --git a/interpreter/src/objects.rs b/interpreter/src/objects.rs
index 5621a27..3e7d8be 100644
--- a/interpreter/src/objects.rs
+++ b/interpreter/src/objects.rs
@@ -267,7 +267,7 @@ impl PartialEq for Value {
             (Value::UInt(a), Value::Float(b)) => (*a as f64) == *b,
             (Value::Float(a), Value::Int(b)) => *a == (*b as f64),
             (Value::Float(a), Value::UInt(b)) => *a == (*b as f64),
-            (a, b) => panic!("unable to compare {:?} with {:?}", a, b),
+            (_, _) => false,
         }
     }
 }
@@ -304,7 +304,7 @@ impl PartialOrd for Value {
             (Value::UInt(a), Value::Float(b)) => (*a as f64).partial_cmp(b),
             (Value::Float(a), Value::Int(b)) => a.partial_cmp(&(*b as f64)),
             (Value::Float(a), Value::UInt(b)) => a.partial_cmp(&(*b as f64)),
-            (a, b) => panic!("unable to compare {:?} with {:?}", a, b),
+            _ => None,
         }
     }
 }
@@ -852,4 +852,14 @@ mod tests {
             "NaN should not be comparable with inequality operators"
         );
     }
+
+    #[test]
+    fn test_invalid_compare() {
+        let context = Context::default();
+
+        let program = Program::compile("size == 50").unwrap();
+        let value = program.execute(&context).unwrap();
+        assert_eq!(value, false.into());
+
+    }
 }
diff --git a/interpreter/src/ser.rs b/interpreter/src/ser.rs
index 71307c6..7872e8f 100644
--- a/interpreter/src/ser.rs
+++ b/interpreter/src/ser.rs
@@ -588,10 +588,8 @@ impl Serialize for Value {
 
 #[cfg(test)]
 mod tests {
-    use crate::objects::Map;
     use crate::{objects::Key, to_value, Value};
     use crate::{Context, Program};
-    use chrono::Duration;
     use serde::Serialize;
     use serde_bytes::Bytes;
     use std::{collections::HashMap, iter::FromIterator, sync::Arc};


Test patch: