Browse Source

Merge pull request #534 from glitch-soc/restructure-kw-as-word-lists

Escape metacharacters in non-whole-word keyword mutes (#463, #533)
closed-social-glitch-2
David Yip 6 years ago
committed by GitHub
parent
commit
68373e799b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions
  1. +1
    -1
      app/models/glitch/keyword_mute.rb
  2. +7
    -1
      spec/models/glitch/keyword_mute_spec.rb

+ 1
- 1
app/models/glitch/keyword_mute.rb View File

@ -50,7 +50,7 @@ class Glitch::KeywordMute < ApplicationRecord
end
def matches?(str)
str =~ (whole_word ? boundary_regex_for_keyword : /#{keyword}/i)
str =~ (whole_word ? boundary_regex_for_keyword : /#{Regexp.escape(keyword)}/i)
end
end

+ 7
- 1
spec/models/glitch/keyword_mute_spec.rb View File

@ -79,12 +79,18 @@ RSpec.describe Glitch::KeywordMute, type: :model do
expect(matcher.matches?('(hot take)')).to be_truthy
end
it 'escapes metacharacters in keywords' do
it 'escapes metacharacters in whole-word keywords' do
Glitch::KeywordMute.create!(account: alice, keyword: '(hot take)')
expect(matcher.matches?('(hot take)')).to be_truthy
end
it 'escapes metacharacters in non-whole-word keywords' do
Glitch::KeywordMute.create!(account: alice, keyword: '(-', whole_word: false)
expect(matcher.matches?('bad (-)')).to be_truthy
end
it 'uses case-folding rules appropriate for more than just English' do
Glitch::KeywordMute.create!(account: alice, keyword: 'großeltern')

Loading…
Cancel
Save