fix: Matching users multiline description correctly
All checks were successful
DCO checker / DCO checker (pull_request) Successful in 22s
Rust CI / Rust CI (pull_request) Successful in 4m22s

fix: #2
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-12-09 22:02:27 +00:00
parent d59b4e6d3f
commit 1eed3f5f86
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),