mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
Merge pull request #214 from glitch-soc/keyword-mute
Maintain case-insensitivity when merging multiple matchers (#213)
This commit is contained in:
commit
bfd9230d61
@ -35,7 +35,7 @@ class Glitch::KeywordMute < ApplicationRecord
|
|||||||
def initialize(account_id)
|
def initialize(account_id)
|
||||||
@account_id = account_id
|
@account_id = account_id
|
||||||
regex_text = Rails.cache.fetch("keyword_mutes:regex:#{account_id}") { regex_text_for_account }
|
regex_text = Rails.cache.fetch("keyword_mutes:regex:#{account_id}") { regex_text_for_account }
|
||||||
@regex = /#{regex_text}/i
|
@regex = /#{regex_text}/
|
||||||
end
|
end
|
||||||
|
|
||||||
def =~(str)
|
def =~(str)
|
||||||
@ -60,7 +60,7 @@ class Glitch::KeywordMute < ApplicationRecord
|
|||||||
sb = keyword =~ /\A[[:word:]]/ ? '\b' : ''
|
sb = keyword =~ /\A[[:word:]]/ ? '\b' : ''
|
||||||
eb = keyword =~ /[[:word:]]\Z/ ? '\b' : ''
|
eb = keyword =~ /[[:word:]]\Z/ ? '\b' : ''
|
||||||
|
|
||||||
/#{sb}#{Regexp.escape(keyword)}#{eb}/
|
/(?mix:#{sb}#{Regexp.escape(keyword)}#{eb})/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -60,6 +60,13 @@ RSpec.describe Glitch::KeywordMute, type: :model do
|
|||||||
expect(matcher =~ 'This is a HOT take').to be_truthy
|
expect(matcher =~ 'This is a HOT take').to be_truthy
|
||||||
end
|
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
|
it 'matches keywords surrounded by non-alphanumeric ornamentation' do
|
||||||
Glitch::KeywordMute.create!(account: alice, keyword: 'hot')
|
Glitch::KeywordMute.create!(account: alice, keyword: 'hot')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user