Repository: freestrings/jsonpath (language: rust)

Issue:
Crash on replace_with
The following crashes:
Where `current_data == {}`

```rust
jsonpath_lib::replace_with(current_data, "$a", &mut |_v| {
})?;
```


Discussion / hints:
It seems like the issue is here: https://github.com/freestrings/jsonpath/blob/5b878d7ba7e17284f8af43fb6d38f1b63a6ca470/src/select/mod.rs#L1061

In case `tokens.len()` is 0 then it crashes.... cause last_index is usize


Fix patch:
diff --git a/src/select/mod.rs b/src/select/mod.rs
index 56c4efe3..e021b340 100644
--- a/src/select/mod.rs
+++ b/src/select/mod.rs
@@ -1058,7 +1058,7 @@ fn replace_value<F: FnMut(Value) -> Option<Value>>(
 ) {
     let mut target = value;
 
-    let last_index = tokens.len() - 1;
+    let last_index = tokens.len().checked_sub(1).unwrap_or(0);
     for (i, token) in tokens.drain(..).enumerate() {
         let target_once = target;
         let is_last = i == last_index;


Test patch: