Merge pull request #451 from glitch-soc/450-make-non-whole-word-mutes-case-insensitive

Also treat non-whole-word mutes as case-insensitive (#450)
rebase/4.0.0rc2
David Yip 2018-04-30 22:38:10 -05:00 committed by GitHub
commit 3a47842223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -70,7 +70,7 @@ class Glitch::KeywordMute < ApplicationRecord
def make_regex_text def make_regex_text
kws = keywords.map! do |whole_word, keyword| kws = keywords.map! do |whole_word, keyword|
whole_word ? boundary_regex_for_keyword(keyword) : keyword whole_word ? boundary_regex_for_keyword(keyword) : /(?i:#{keyword})/
end end
Regexp.union(kws).source Regexp.union(kws).source

View File

@ -60,6 +60,12 @@ RSpec.describe Glitch::KeywordMute, type: :model do
expect(matcher.matches?('This is a HOT take')).to be_truthy expect(matcher.matches?('This is a HOT take')).to be_truthy
end end
it 'matches if at least one non-whole-word keyword case-insensitively matches the text' do
Glitch::KeywordMute.create!(account: alice, keyword: 'hot', whole_word: false)
expect(matcher.matches?('This is a HOTTY take')).to be_truthy
end
it 'maintains case-insensitivity when combining keywords into a single matcher' do it 'maintains case-insensitivity when combining keywords into a single matcher' do
Glitch::KeywordMute.create!(account: alice, keyword: 'hot') Glitch::KeywordMute.create!(account: alice, keyword: 'hot')
Glitch::KeywordMute.create!(account: alice, keyword: 'cold') Glitch::KeywordMute.create!(account: alice, keyword: 'cold')