fix: Matching users multiline description correctly #3

Manually merged
awiteb merged 1 commit from awiteb/fix-2 into master 2024-12-09 23:32:34 +01:00 AGit

View file

@ -28,10 +28,16 @@ pub trait ExprChecker {
impl ExprChecker for Expr {
fn is_match<'a>(&'a self, user: &ForgejoUser) -> Option<RegexReason> {
let one_of = |hay: &str, exprs: &'a Vec<RegexReason>| {
exprs.iter().find(|re| {
hay.split('\n')
.any(|line| re.re_vec.iter().all(|re| re.is_match(line.trim())))
})
// Join the user bio into a single line
// ref: https://git.4rs.nl/awiteb/forgejo-guardian/issues/2
let hay = if hay.contains('\n') {
hay.split('\n').collect::<Vec<_>>().join(" ")
} else {
hay.to_string()
};
exprs
.iter()
.find(|re_re| re_re.re_vec.iter().all(|re| re.is_match(&hay)))
};
[
one_of(&user.username, &self.usernames),