From 5b3fd544ba3cdef6aea392ada24cb6df0e3aade8 Mon Sep 17 00:00:00 2001 From: Trevor Hilton Date: Sun, 12 May 2024 17:53:38 -0400 Subject: [PATCH] fix: use CRLF mode in regexes for match and search (#92) Update after latest CTS surfaced an edge case for i-regexp compliance. Use CRLF mode in regexes for search and match functions so that the line feed and new line characters are treated properly with a dot matcher --- jsonpath-compliance-test-suite | 2 +- serde_json_path/CHANGELOG.md | 4 ++++ .../src/parser/selector/function/registry.rs | 20 +++++++++++-------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/jsonpath-compliance-test-suite b/jsonpath-compliance-test-suite index 31dec17..7c8e9bc 160000 --- a/jsonpath-compliance-test-suite +++ b/jsonpath-compliance-test-suite @@ -1 +1 @@ -Subproject commit 31dec1720dc9b9d3e8af3c61f025da93ceb6c9d1 +Subproject commit 7c8e9bcd92f8ed8797331de02f488ebcb7856bec diff --git a/serde_json_path/CHANGELOG.md b/serde_json_path/CHANGELOG.md index 4778ee3..d233e8b 100644 --- a/serde_json_path/CHANGELOG.md +++ b/serde_json_path/CHANGELOG.md @@ -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]) diff --git a/serde_json_path/src/parser/selector/function/registry.rs b/serde_json_path/src/parser/selector/function/registry.rs index e52a3fc..1a9e88d 100644 --- a/serde_json_path/src/parser/selector/function/registry.rs +++ b/serde_json_path/src/parser/selector/function/registry.rs @@ -53,10 +53,12 @@ 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, } } @@ -64,10 +66,12 @@ fn match_func(value: ValueType, rgx: ValueType) -> LogicalType { #[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, } }