Browse Source

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
pull/4/head
Eugen Rochko 5 years ago
committed by GitHub
parent
commit
404c7702ec
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions
  1. +1
    -1
      app/javascript/mastodon/selectors/index.js
  2. +3
    -2
      app/lib/feed_manager.rb

+ 1
- 1
app/javascript/mastodon/selectors/index.js View File

@ -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 = () => {

+ 3
- 2
app/lib/feed_manager.rb View File

@ -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

Loading…
Cancel
Save