Skip to content

Commit

Permalink
Merge branch 'main' into compliance-badge
Browse files Browse the repository at this point in the history
  • Loading branch information
hiltontj committed May 12, 2024
2 parents 786e45f + 5b3fd54 commit 2e0c04c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion jsonpath-compliance-test-suite
4 changes: 4 additions & 0 deletions serde_json_path/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

- **fixed**: edge case where `.` in regexes for `match` and `search` functions was matching `\r\n` properly ([#92])

[#92]: https://github.com/hiltontj/serde_json_path/pull/92

# 0.6.7 (3 March 2024)

- **testing**: support tests for non-determinism in compliance test suite ([#85])
Expand Down
20 changes: 12 additions & 8 deletions serde_json_path/src/parser/selector/function/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,25 @@ 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())
.map(|r| r.is_match(s))
.map(Into::into)
.unwrap_or_default(),
(Some(Value::String(s)), Some(Value::String(r))) => {
Regex::new(format!("(?R)^({r})$").as_str())
.map(|r| r.is_match(s))
.map(Into::into)
.unwrap_or_default()
}
_ => LogicalType::False,
}
}

#[serde_json_path_macros::register(target = SEARCH_FUNC)]
fn search(value: ValueType, rgx: ValueType) -> LogicalType {
match (value.as_value(), rgx.as_value()) {
(Some(Value::String(s)), Some(Value::String(r))) => Regex::new(r.as_str())
.map(|r| r.is_match(s))
.map(Into::into)
.unwrap_or_default(),
(Some(Value::String(s)), Some(Value::String(r))) => {
Regex::new(format!("(?R)({r})").as_str())
.map(|r| r.is_match(s))
.map(Into::into)
.unwrap_or_default()
}
_ => LogicalType::False,
}
}
Expand Down

0 comments on commit 2e0c04c

Please sign in to comment.