about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2018-07-09 02:22:09 +0200
committerEugen Rochko <eugen@zeonfederated.com>2018-07-09 02:22:09 +0200
commit1ca4e51eb38de6de81cedf3ddcdaa626f1d1c569 (patch)
tree3cf44ef95b178d233fd34d2ec2aae2a7021c159d /app/lib
parent451e585b9720c61ef9a155a16484b25ded79d512 (diff)
Add option to not consider word boundaries when processing keyword filtering (#7975)
* Add option to not consider word boundaries when filtering phrases

* Add a few tests for keyword/phrase filtering
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/feed_manager.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index 55c72d0ea..c247ab21d 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -200,7 +200,16 @@ class FeedManager
     active_filters = Rails.cache.fetch("filters:#{receiver_id}") { CustomFilter.where(account_id: receiver_id).active_irreversible.to_a }.to_a
 
     active_filters.select! { |filter| filter.context.include?(context.to_s) && !filter.expired? }
-    active_filters.map! { |filter| Regexp.new("\\b#{Regexp.escape(filter.phrase)}\\b", true) }
+    active_filters.map! do |filter|
+      if filter.whole_word
+        sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : ''
+        eb = filter.phrase =~ /[[:word:]]\Z/ ? '\b' : ''
+
+        /(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/
+      else
+        /#{Regexp.escape(filter.phrase)}/i
+      end
+    end
 
     return false if active_filters.empty?