From 1f72998b54b543b6714c2684d8b59067ed969e2e Mon Sep 17 00:00:00 2001 From: lifegpc Date: Thu, 10 Mar 2022 23:50:43 +0800 Subject: [PATCH] Minor fix for author-name-filters --- src/author_name_filter.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/author_name_filter.rs b/src/author_name_filter.rs index 79b5426..b98a154 100644 --- a/src/author_name_filter.rs +++ b/src/author_name_filter.rs @@ -59,13 +59,13 @@ impl AuthorFiler for AuthorNameFilter { fn filter(&self, author: &str) -> String { match self { Self::Simple(s) => { - match author.find(s) { + match author.rfind(s) { Some(i) => { String::from(&author[..i]) } None => { String::from(author) } } } Self::Regex(r) => { - r.replace(author, "").to_owned().to_string() + r.replace_all(author, "").to_owned().to_string() } } } @@ -153,4 +153,6 @@ fn test_author_name_filter() { let l = AuthorNameFilter::from_json(json::array![{"type": "simple", "rule": "🌸"}, {"type": "regex", "rule": ".?お仕事募集中"}]).unwrap(); assert_eq!(l, vec![AuthorNameFilter::from("🌸"), AuthorNameFilter::from(r)]); assert_eq!(l.filter("moco<お仕事募集中🌸お仕事募集中"), String::from("moco<お仕事募集中")); + assert_eq!(l.filter("sss@ss@お仕事募集中"), "sss@ss"); + assert_eq!(l.filter("sss🌸ss🌸お仕事募集中"), "sss🌸ss"); }