Skip to content

Commit

Permalink
enclose match regex in parens to match full string
Browse files Browse the repository at this point in the history
  • Loading branch information
hiltontj committed Sep 15, 2023
1 parent 9f463fc commit bc1c0f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion serde_json_path/src/parser/selector/function/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn count(nodes: NodesType) -> ValueType {
#[serde_json_path_macros::register(name = "match", target = MATCH_FUNC)]
fn match_func(value: ValueType, rgx: ValueType) -> LogicalType {
match (value.as_value(), rgx.as_value()) {
(Some(Value::String(s)), Some(Value::String(r))) => Regex::new(format!("^{r}$").as_str())
(Some(Value::String(s)), Some(Value::String(r))) => Regex::new(format!("^({r})$").as_str())
.map(|r| r.is_match(s))
.map(Into::into)
.unwrap_or_default(),
Expand Down
9 changes: 9 additions & 0 deletions serde_json_path/tests/regressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ fn issue_49() {
let path = JsonPath::parse("$[?(@.a == 2)]").expect("parses JSONPath");
assert!(path.query(&value).is_empty());
}

// This test is meant for issue #60, which can be found here:
// https://github.com/hiltontj/serde_json_path/issues/60
#[test]
fn issue_60() {
let value = json!([{"foo": "bar"}, {"foo": "biz"}]);
let path = JsonPath::parse("$[? match(@.foo, '|')]").expect("parses JSONPath");
assert!(path.query(&value).is_empty());
}

0 comments on commit bc1c0f4

Please sign in to comment.