Skip to content

Commit

Permalink
fix: return error for incorrect Some matching
Browse files Browse the repository at this point in the history
  • Loading branch information
qjerome committed Jul 16, 2024
1 parent 652de9c commit aba5f8b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion gene/src/rules/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,14 @@ impl DirectMatch {
Err(())
},
)
.or(Ok(fv.is_some() && matches!(self.value, MatchValue::Some))),
.or(
// we return Ok only if we want to match some
if matches!(self.value, MatchValue::Some) {
Ok(fv.is_some())
} else {
Err(())
},
),
Op::Gt => cmp_values!(Number, fv, >, self.value),
Op::Gte => cmp_values!(Number, fv, >=, self.value),
Op::Lt => cmp_values!(Number, fv, <, self.value),
Expand Down Expand Up @@ -423,6 +430,12 @@ mod test {
.unwrap()
.match_value(&FieldValue::None)
.unwrap());

// we try to match None against a string so we must return an error
assert!(DirectMatch::from_str(r#".data is 'toast'"#)
.unwrap()
.match_value(&FieldValue::None)
.is_err());
}

#[test]
Expand Down

0 comments on commit aba5f8b

Please sign in to comment.