Fix matching numbers against the regex
Still, `Null`, `Bool`, `Array` and `Object` types are unmatchable. Work TBD...
This commit is contained in:
parent
7f143e0b08
commit
ea3121a985
1 changed files with 26 additions and 16 deletions
30
src/main.rs
30
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,8 +211,16 @@ 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) {
|
||||
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!(),
|
||||
};
|
||||
|
||||
if regex.is_match(&value) {
|
||||
debug!("Filter `{}` of hook `{}` matched", filter_name, hook_name);
|
||||
|
||||
return Ok(Some(replace_parameter(
|
||||
|
@ -212,16 +229,9 @@ fn filter_match(
|
|||
data,
|
||||
)?));
|
||||
}
|
||||
} else {
|
||||
bail!(
|
||||
"Could not parse pointer in hook `{}` from filter `{}`",
|
||||
hook_name,
|
||||
filter_name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
trace!(
|
||||
debug!(
|
||||
"Filter `{}` of hook `{}` did not match",
|
||||
filter_name,
|
||||
hook_name
|
||||
|
|
Loading…
Reference in a new issue