Skip to content

Commit

Permalink
fix: validate jq program compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
8e8b2c committed Aug 1, 2024
1 parent 907f6ef commit 8dcb94d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions crates/username_registry_validation/src/recipe.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8dcb94d

Please sign in to comment.