about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-07-06 02:15:44 +0200
committerGitHub <noreply@github.com>2018-07-06 02:15:44 +0200
commit404c7702ec2a6576ef3b54f6a800624adfda9d53 (patch)
tree80c543822195128f73b7f4f234dc7624cf136cea /app
parent17b928502a968d8051fd3dc31be046aba96fde6f (diff)
In keyword filter, account for reblogs, HTML and whole-words (#7960)
* In keyword filter, account for reblogs, HTML and whole-words

* Match whole words in JS filter, too

* Fix typo
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/selectors/index.js2
-rw-r--r--app/lib/feed_manager.rb5
2 files changed, 4 insertions, 3 deletions
diff --git a/app/javascript/mastodon/selectors/index.js b/app/javascript/mastodon/selectors/index.js
index 56eca1f02..ba9777eba 100644
--- a/app/javascript/mastodon/selectors/index.js
+++ b/app/javascript/mastodon/selectors/index.js
@@ -43,7 +43,7 @@ const regexFromFilters = filters => {
     return null;
   }
 
-  return new RegExp(filters.map(filter => escapeRegExp(filter.get('phrase'))).join('|'), 'i');
+  return new RegExp(filters.map(filter => escapeRegExp(filter.get('phrase'))).map(expr => `\\b${expr}\\b`).join('|'), 'i');
 };
 
 export const makeGetStatus = () => {
diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb
index efe7e2b7b..55c72d0ea 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -200,13 +200,14 @@ 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(Regexp.escape(filter.phrase), true) }
+    active_filters.map! { |filter| Regexp.new("\\b#{Regexp.escape(filter.phrase)}\\b", true) }
 
     return false if active_filters.empty?
 
     combined_regex = active_filters.reduce { |memo, obj| Regexp.union(memo, obj) }
+    status         = status.reblog if status.reblog?
 
-    !combined_regex.match(status.text).nil? ||
+    !combined_regex.match(Formatter.instance.plaintext(status)).nil? ||
       (status.spoiler_text.present? && !combined_regex.match(status.spoiler_text).nil?)
   end