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

[#49] Fix bug producing false positives in filters #50

Merged
merged 5 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions serde_json_path/tests/regressions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use serde_json::json;
use serde_json_path::JsonPath;
#[cfg(feature = "trace")]
use test_log::test;

// This test is meant for issue #49, which can be found here:
// https://github.com/hiltontj/serde_json_path/issues/49
#[test]
fn issue_49() {
let value = json!({"a": 1, "b": 2});
let path = JsonPath::parse("$[?(@.a == 2)]").expect("parses JSONPath");
assert!(path.query(&value).is_empty());
}
6 changes: 6 additions & 0 deletions serde_json_path_core/src/spec/selector/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ impl std::fmt::Display for Comparable {

impl Comparable {
#[doc(hidden)]
#[cfg_attr(feature = "trace", tracing::instrument(name = "Comparable::as_value", level = "trace", parent = None, ret))]
pub fn as_value<'a, 'b: 'a>(
&'a self,
current: &'b Value,
Expand Down Expand Up @@ -493,6 +494,7 @@ pub struct SingularQuery {

impl SingularQuery {
/// Evaluate the singular query
#[cfg_attr(feature = "trace", tracing::instrument(name = "SingularQuery::eval_query", level = "trace", parent = None, ret))]
pub fn eval_query<'b>(&self, current: &'b Value, root: &'b Value) -> Option<&'b Value> {
let mut target = match self.kind {
SingularQueryKind::Absolute => root,
Expand All @@ -507,6 +509,8 @@ impl SingularQuery {
} else {
return None;
}
} else {
return None;
}
}
SingularQuerySegment::Index(index) => {
Expand All @@ -516,6 +520,8 @@ impl SingularQuery {
} else {
return None;
}
} else {
return None;
}
}
}
Expand Down