Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug found with new CTS #84

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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**: 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])
Expand Down
7 changes: 7 additions & 0 deletions serde_json_path/src/parser/selector/function/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashMap<&'static str, &'static Function>> = Lazy::new(|| {
let mut m = HashMap::new();
m.insert("length", &LENGTH_FUNC);
Expand Down
4 changes: 4 additions & 0 deletions serde_json_path_core/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**: 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])
Expand Down
26 changes: 24 additions & 2 deletions serde_json_path_core/src/spec/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionArgType> {
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
Expand Down
4 changes: 4 additions & 0 deletions serde_json_path_macros/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**: 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
Expand Down
Loading