diff --git a/serde_json_path/src/parser/selector/function/registry.rs b/serde_json_path/src/parser/selector/function/registry.rs index aa6daf6..bc88636 100644 --- a/serde_json_path/src/parser/selector/function/registry.rs +++ b/serde_json_path/src/parser/selector/function/registry.rs @@ -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(), diff --git a/serde_json_path/tests/regressions.rs b/serde_json_path/tests/regressions.rs index c53b3b5..7f1f940 100644 --- a/serde_json_path/tests/regressions.rs +++ b/serde_json_path/tests/regressions.rs @@ -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()); +}