Repository: freestrings/jsonpath (language: rust)

Issue:
Crash using Filter with $ 



Discussion / hints:
Add the following test to `tests/filter.rs`
```
#[test]
fn unsupported_in_filter() {
    setup();

    let json = json!([{
        "a": {"x": {"i": 10}},
        "b": {"x": {"i": 20, "j": 5}}
    }]);

    select_and_then_compare("$..x[?(@.i>10)]", json.clone(), json!([{"i": 20,"j": 5}]));

    // Should not panic ('empty term left')
    select_and_then_compare("$..x[?($.i>10)]", json.clone(), json!([]));
}

```
The filter `?($.i>10)` panics
---- unsupported_in_filter stdout ----
thread 'unsupported_in_filter' panicked at 'empty term left', src/selector/selector_impl.rs:344:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


Fix patch:
diff --git a/src/select/mod.rs b/src/select/mod.rs
index 7da78422..840a87ba 100644
--- a/src/select/mod.rs
+++ b/src/select/mod.rs
@@ -650,7 +650,7 @@ impl<'a, 'b> Selector<'a, 'b> {
                     _ => unreachable!(),
                 },
             ),
-            _ => panic!("empty term right"),
+            _ => ExprTerm::Json(None, None, vec![]), //panic!("empty term right"),
         };
 
         let left = match self.selector_filter.pop_term() {
@@ -663,7 +663,6 @@ impl<'a, 'b> Selector<'a, 'b> {
                     _ => unreachable!(),
                 },
             ),
-            _ => panic!("empty term left"),
         };
 
         let mut ret = None;
diff --git a/src/selector/selector_impl.rs b/src/selector/selector_impl.rs
index 84eb24be..3a4655c2 100644
--- a/src/selector/selector_impl.rs
+++ b/src/selector/selector_impl.rs
@@ -328,7 +328,7 @@ impl<'a> JsonSelector<'a> {
                     _ => unreachable!(),
                 },
             ),
-            _ => panic!("empty term right"),
+            _ => ExprTerm::Json(None, None, vec![]), //panic!("empty term right"),
         };
 
         let mut left = match self.selector_filter.pop_term() {
@@ -341,7 +341,7 @@ impl<'a> JsonSelector<'a> {
                     _ => unreachable!(),
                 },
             ),
-            _ => panic!("empty term left"),
+            _ => ExprTerm::Json(None, None, vec![]), //panic!("empty term left"),
         };
 
         let expr = match ft {


Test patch:
diff --git a/tests/filter.rs b/tests/filter.rs
index c847dab3..bed76f60 100644
--- a/tests/filter.rs
+++ b/tests/filter.rs
@@ -277,4 +277,19 @@ fn bugs38_array_notation_in_filter() {
          ]),
         json!([{"seq": 2, "subKey": "subKey2"}]),
     );
-}
\ No newline at end of file
+}
+
+#[test]
+fn unsupported_in_filter() {
+    setup();
+
+    let json = json!([{
+        "a": {"x": {"i": 10}},
+        "b": {"x": {"i": 20, "j": 5}}
+    }]);
+
+    select_and_then_compare("$..x[?(@.i>10)]", json.clone(), json!([{"i": 20,"j": 5}]));
+
+    // Should not panic ('empty term left')
+    select_and_then_compare("$..x[?($.i>10)]", json.clone(), json!([]));
+}