FIX: Make sure censored words are on boundaries in topic titles

This commit is contained in:
Robin Ward 2017-06-28 13:13:40 -04:00
parent c1560d8195
commit b93edc9945
2 changed files with 10 additions and 2 deletions

View File

@ -33,7 +33,7 @@ class CensoredWordsValidator < ActiveModel::EachValidator
def censored_words_regexp
Regexp.new(
SiteSetting.censored_words.split('|'.freeze).map! { |w| Regexp.escape(w) }.join('|'.freeze),
'\b(' + SiteSetting.censored_words.split('|'.freeze).map! { |w| Regexp.escape(w) }.join('|'.freeze) + ')\b',
true
)
end

View File

@ -34,7 +34,7 @@ describe Topic do
it 'should not be valid' do
SiteSetting.censored_words = 'pineapple|pen'
topic.title = 'pen PinEapple apple pen '
topic.title = 'pen PinEapple apple pen is a complete sentence'
expect(topic).to_not be_valid
@ -44,6 +44,14 @@ describe Topic do
end
end
describe 'titles with censored words not on boundaries' do
it "should be valid" do
SiteSetting.censored_words = 'apple'
topic.title = "Pineapples are great fruit! Applebee's is a great restaurant"
expect(topic).to be_valid
end
end
describe 'when title does not contain censored words' do
it 'should be valid' do
topic.title = 'The cake is a lie'