about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2017-11-13 12:33:19 -0600
committerGitHub <noreply@github.com>2017-11-13 12:33:19 -0600
commitbfd9230d61effe537874f02de87b6415bae45ae1 (patch)
treef1269f1ccc89ae14d119ed97a1eeaf121c14b6c7
parente1b7785788aa3887b06a5b2b10731b4b5d66d7e3 (diff)
parent656d54e9451dc99e212513b799a4deb4d1227bf0 (diff)
Merge pull request #214 from glitch-soc/keyword-mute
Maintain case-insensitivity when merging multiple matchers (#213)
-rw-r--r--app/models/glitch/keyword_mute.rb4
-rw-r--r--spec/models/glitch/keyword_mute_spec.rb7
2 files changed, 9 insertions, 2 deletions
diff --git a/app/models/glitch/keyword_mute.rb b/app/models/glitch/keyword_mute.rb
index 73de4d4b7..009de1880 100644
--- a/app/models/glitch/keyword_mute.rb
+++ b/app/models/glitch/keyword_mute.rb
@@ -35,7 +35,7 @@ class Glitch::KeywordMute < ApplicationRecord
     def initialize(account_id)
       @account_id = account_id
       regex_text = Rails.cache.fetch("keyword_mutes:regex:#{account_id}") { regex_text_for_account }
-      @regex = /#{regex_text}/i
+      @regex = /#{regex_text}/
     end
 
     def =~(str)
@@ -60,7 +60,7 @@ class Glitch::KeywordMute < ApplicationRecord
       sb = keyword =~ /\A[[:word:]]/ ? '\b' : ''
       eb = keyword =~ /[[:word:]]\Z/ ? '\b' : ''
 
-      /#{sb}#{Regexp.escape(keyword)}#{eb}/
+      /(?mix:#{sb}#{Regexp.escape(keyword)}#{eb})/
     end
   end
 end
diff --git a/spec/models/glitch/keyword_mute_spec.rb b/spec/models/glitch/keyword_mute_spec.rb
index 1423823ba..9685c6493 100644
--- a/spec/models/glitch/keyword_mute_spec.rb
+++ b/spec/models/glitch/keyword_mute_spec.rb
@@ -60,6 +60,13 @@ RSpec.describe Glitch::KeywordMute, type: :model do
         expect(matcher =~ 'This is a HOT take').to be_truthy
       end
 
+      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: 'cold')
+
+        expect(matcher =~ 'This is a HOT take').to be_truthy
+      end
+
       it 'matches keywords surrounded by non-alphanumeric ornamentation' do
         Glitch::KeywordMute.create!(account: alice, keyword: 'hot')