From 8dcb94dfbc8bc394d11c97dbe0a5af91c0e0a56b Mon Sep 17 00:00:00 2001 From: 8e8b2c <8e8b2c@proton.me> Date: Thu, 1 Aug 2024 11:44:39 +0100 Subject: [PATCH] fix: validate jq program compilation --- .../username_registry_validation/src/recipe.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/username_registry_validation/src/recipe.rs b/crates/username_registry_validation/src/recipe.rs index 0f61d2c..0b0ad5f 100644 --- a/crates/username_registry_validation/src/recipe.rs +++ b/crates/username_registry_validation/src/recipe.rs @@ -1,5 +1,6 @@ use hdi::prelude::*; use holoom_types::recipe::{JqInstructionArgumentNames, Recipe, RecipeInstruction}; +use jaq_wrapper::compile_filter; pub fn validate_create_recipe( _action: EntryCreationAction, @@ -39,11 +40,17 @@ pub fn validate_create_recipe( RecipeInstruction::GetDocsListedByVar { var_name } => vec![var_name], RecipeInstruction::GetLatestDocWithIdentifier { var_name } => vec![var_name], RecipeInstruction::Jq { - input_var_names, .. - } => match input_var_names { - JqInstructionArgumentNames::List { var_names } => var_names, - JqInstructionArgumentNames::Single { var_name } => vec![var_name], - }, + input_var_names, + program, + } => { + if compile_filter(&program).is_err() { + return Ok(ValidateCallbackResult::Invalid("Invalid jq program".into())); + } + match input_var_names { + JqInstructionArgumentNames::List { var_names } => var_names, + JqInstructionArgumentNames::Single { var_name } => vec![var_name], + } + } }; for dependency in var_dependencies { if !declared_vars_names.contains(&dependency) {