From a3eeb38e5f8b8ebc0cdd193b823c1a4804830133 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 25 Nov 2024 02:30:56 +0100 Subject: [PATCH] fix(tasks): fallback upon invalid regex --- src/tasks.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tasks.rs b/src/tasks.rs index c0d3f8d..c559015 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -859,8 +859,8 @@ impl TasksRelay { return vec![id]; } let lowercase_arg = arg.to_ascii_lowercase(); - // TODO apply regex to all matching - let regex = Regex::new(&format!(r"\b{}", lowercase_arg)).unwrap(); + // TODO apply regex to all matching, parse as plain match + let regex = Regex::new(&format!(r"\b{}", lowercase_arg)); let mut filtered: Vec = Vec::with_capacity(32); let mut filtered_fuzzy: Vec = Vec::with_capacity(32); @@ -871,7 +871,9 @@ impl TasksRelay { return vec![task.event.id]; } else if content.starts_with(arg) { filtered.push(task.event.id) - } else if regex.is_match(lowercase.as_bytes()) { + } else if regex.as_ref() + .map(|r| r.is_match(lowercase.as_bytes())) + .unwrap_or_else(|_| lowercase.starts_with(&lowercase_arg)) { filtered_fuzzy.push(task.event.id) } }