Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using replace leads to a panic #1

Closed
stefanpieck opened this issue Feb 6, 2022 · 2 comments
Closed

Using replace leads to a panic #1

stefanpieck opened this issue Feb 6, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@stefanpieck
Copy link

For my use case I need to remove values for specific conditions.

I tried to do that by use the replace method, but ran into a panic when using replace at all.

Occured on version 0.1.0

Here a short test to reproduce:

#[test]
fn test_replace() {
    let input = json!({"list": ["red", "green", "blue"]});
    let path = jsonpath_plus::JsonPath::compile("$.list[*]").expect("jsonpath is valid");
    let output = path.replace(&input, |_| json!("black"));
    assert_eq!(output, json!({"list": ["black", "black", "black"]}))
}

The output was:

thread 'tests::test_replace' panicked at 'explicit panic', /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.0/src/eval.rs:39:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:107:14
   2: core::panicking::panic
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:48:5
   3: jsonpath_plus::eval::Idx::as_string
             at /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.0/src/eval.rs:39:18
   4: jsonpath_plus::resolve_path
             at /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.0/src/lib.rs:40:53
   5: jsonpath_plus::<impl jsonpath_plus::ast::Path>::replace
             at /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.0/src/lib.rs:132:30
   6: jsonpath_filter::tests::test_replace
             at ./src/lib.rs:223:22
   7: jsonpath_filter::tests::test_replace::{{closure}}
             at ./src/lib.rs:220:5
   8: core::ops::function::FnOnce::call_once
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/ops/function.rs:227:5
   9: core::ops::function::FnOnce::call_once
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test tests::test_replace ... FAILED
@CraftSpider
Copy link
Owner

Published the fix in version as 0.1.1. This should also fix JsonPath::delete, which uses the same code path.

@CraftSpider CraftSpider added the bug Something isn't working label Feb 7, 2022
@stefanpieck
Copy link
Author

Issue is fixed in version 0.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants