From 8c1e39708fc817dc981a97c09efd9bfb38baa649 Mon Sep 17 00:00:00 2001 From: tretrauit Date: Wed, 10 Jan 2024 15:32:30 +0700 Subject: [PATCH] fix(katana): only regex if the word length is > 2 --- swordfish/src/katana.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/swordfish/src/katana.rs b/swordfish/src/katana.rs index f2a2d7d..2bca7c2 100644 --- a/swordfish/src/katana.rs +++ b/swordfish/src/katana.rs @@ -178,11 +178,14 @@ fn regexify_text(text: &String) -> String { ascii_text.push(' '); } } - ascii_text.split_whitespace().for_each(|word| { + for word in ascii_text.split_whitespace() { + if word.len() < 2 && regex.len() > 0 { + continue; + } regex.push_str("(?=.*\\b"); regex.push_str(word.to_lowercase().as_str()); regex.push_str("\\b)"); - }); + } regex.push_str(".+"); trace!("Regex: {}", regex); regex