diff --git a/jsonpath-compliance-test-suite b/jsonpath-compliance-test-suite index ca076c0..446336c 160000 --- a/jsonpath-compliance-test-suite +++ b/jsonpath-compliance-test-suite @@ -1 +1 @@ -Subproject commit ca076c0e55d378236e7b70fc8e6414234dcca294 +Subproject commit 446336cd6651586f416a3b546c70bdd0fa2022c0 diff --git a/serde_json_path/CHANGELOG.md b/serde_json_path/CHANGELOG.md index 64831f0..05d8818 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**: bug preventing registered functions from being used as arguments to other functions ([#84]) + +[#84]: https://github.com/hiltontj/serde_json_path/pull/84 + # 0.6.6 (23 February 2024) - **docs**: update links to refer to RFC 9535 ([#81]) diff --git a/serde_json_path/src/parser/selector/function/registry.rs b/serde_json_path/src/parser/selector/function/registry.rs index bc88636..e52a3fc 100644 --- a/serde_json_path/src/parser/selector/function/registry.rs +++ b/serde_json_path/src/parser/selector/function/registry.rs @@ -9,6 +9,13 @@ use serde_json_path_core::spec::functions::{Function, LogicalType, NodesType, Va /// /// These come directly from the JSONPath specification, which includes a registry of standardized /// functions. +/// +/// # Note +/// +/// There is a function in `serde_json_path_core/src/spec/functions.rs` that gives +/// the return type for each function registered here. When adding new functions to +/// the register, i.e., when new functions are standardized, the function there needs +/// to be updated too. pub(crate) static REGISTRY: Lazy> = Lazy::new(|| { let mut m = HashMap::new(); m.insert("length", &LENGTH_FUNC); diff --git a/serde_json_path_core/CHANGELOG.md b/serde_json_path_core/CHANGELOG.md index 3914a52..59ce670 100644 --- a/serde_json_path_core/CHANGELOG.md +++ b/serde_json_path_core/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased +- **fixed**: bug preventing registered functions from being used as arguments to other functions ([#84]) + +[#84]: https://github.com/hiltontj/serde_json_path/pull/84 + # 0.1.5 (23 February 2024) - **docs**: update links to refer to RFC 9535 ([#81]) diff --git a/serde_json_path_core/src/spec/functions.rs b/serde_json_path_core/src/spec/functions.rs index c6a4abc..3a8d00b 100644 --- a/serde_json_path_core/src/spec/functions.rs +++ b/serde_json_path_core/src/spec/functions.rs @@ -618,14 +618,36 @@ impl FunctionExprArg { return Ok(f.result_type); } } - Err(FunctionValidationError::Undefined { - name: func.name.to_owned(), + registered_function_result_type(&func.name).ok_or_else(|| { + FunctionValidationError::Undefined { + name: func.name.to_owned(), + } }) } } } } +/// Get the result type of a registered function +/// +/// This is a hack, but must be done, because the REGISTRY defined in `serde_json_path` +/// is not accessible here. Therefore, this must also be maintained when new functions +/// are added to the registry in the standard. +/// +/// An alternative would be to define the registry of functions in core, we would then +/// just not have the convenience macro for defining them, along with their validators +/// and evaluators. +fn registered_function_result_type(name: &str) -> Option { + match name { + "length" => Some(FunctionArgType::Value), + "count" => Some(FunctionArgType::Value), + "match" => Some(FunctionArgType::Logical), + "search" => Some(FunctionArgType::Logical), + "value" => Some(FunctionArgType::Value), + _ => None, + } +} + /// Function argument types /// /// This is used to describe the type of a function argument to determine if it will be valid as a diff --git a/serde_json_path_macros/CHANGELOG.md b/serde_json_path_macros/CHANGELOG.md index d4d06ac..27e8930 100644 --- a/serde_json_path_macros/CHANGELOG.md +++ b/serde_json_path_macros/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased +- **fixed**: bug preventing registered functions from being used as arguments to other functions ([#84]) + +[#84]: https://github.com/hiltontj/serde_json_path/pull/84 + # 0.1.3 (23 February 2024) - **internal**: update serde_json_path_core dependency