From 3d6b49c01a61d6ee18da488dbc1d1fbf5caedf3c Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 10 Dec 2024 01:21:52 +0300
Subject: [PATCH] fix: Matching users multiline description correctly
Reported-by: Awiteb
Fixes: https://git.4rs.nl/awiteb/forgejo-guardian/issues/2
Signed-off-by: Awiteb
---
src/traits.rs | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/traits.rs b/src/traits.rs
index 99e857d..c2a2c58 100644
--- a/src/traits.rs
+++ b/src/traits.rs
@@ -28,10 +28,16 @@ pub trait ExprChecker {
impl ExprChecker for Expr {
fn is_match<'a>(&'a self, user: &ForgejoUser) -> Option {
let one_of = |hay: &str, exprs: &'a Vec| {
- 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::>().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),