diff --git a/src/main.rs b/src/main.rs index 1d2d6db..01ee2e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -189,6 +189,15 @@ fn replace_parameter(input: &str, headers: &HeaderMap, data: &serde_json::Value) Ok(result.join("")) } +fn number_to_string(number: &serde_json::Number) -> String { + if number.is_f64() { + return number.as_f64().unwrap().to_string(); + } else if number.is_i64() { + return number.as_i64().unwrap().to_string(); + } + number.as_u64().unwrap().to_string() +} + fn filter_match( hook_name: &str, hook: &Hook, @@ -202,26 +211,27 @@ fn filter_match( let regex = Regex::new(&filter.regex)?; if let Some(value) = data.pointer(&filter.pointer) { - if let Some(value) = value.as_str() { - if regex.is_match(value) { - debug!("Filter `{}` of hook `{}` matched", filter_name, hook_name); + let value = match &value { + serde_json::Value::Null => unimplemented!(), + serde_json::Value::Bool(_bool) => unimplemented!(), + serde_json::Value::Number(number) => number_to_string(number), + serde_json::Value::String(string) => string.as_str().to_string(), + serde_json::Value::Array(_array) => unimplemented!(), + serde_json::Value::Object(_object) => unimplemented!(), + }; - return Ok(Some(replace_parameter( - &hook.command.to_string(), - &request.headers(), - data, - )?)); - } - } else { - bail!( - "Could not parse pointer in hook `{}` from filter `{}`", - hook_name, - filter_name - ); + if regex.is_match(&value) { + debug!("Filter `{}` of hook `{}` matched", filter_name, hook_name); + + return Ok(Some(replace_parameter( + &hook.command.to_string(), + &request.headers(), + data, + )?)); } } - trace!( + debug!( "Filter `{}` of hook `{}` did not match", filter_name, hook_name