From 1eed3f5f8625b03fceea557bfd99bf2ee03a3f4e Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Mon, 9 Dec 2024 22:02:27 +0000
Subject: [PATCH] fix: Matching users multiline description correctly
fix: 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),
--
2.45.2