fix: Matching users multiline description correctly
All checks were successful
Write changelog / write-changelog (push) Successful in 6s
Rust CI / Rust CI (push) Successful in 3m39s

Reported-by: Awiteb <a@4rs.nl>
Fixes: #2
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-12-10 01:21:52 +03:00
parent 7a0f3fab27
commit 3d6b49c01a
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

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),