mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:29:30 +08:00
FIX: don't downcase watched words on input since it can break the watched_words_regular_expressions setting
This commit is contained in:
parent
daad2291ba
commit
8f21c96ea5
|
@ -31,11 +31,12 @@ class WatchedWord < ActiveRecord::Base
|
||||||
scope :by_action, -> { order("action ASC, word ASC") }
|
scope :by_action, -> { order("action ASC, word ASC") }
|
||||||
|
|
||||||
def self.normalize_word(w)
|
def self.normalize_word(w)
|
||||||
w.strip.downcase.squeeze('*')
|
w.strip.squeeze('*')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_or_update_word(params)
|
def self.create_or_update_word(params)
|
||||||
w = find_or_initialize_by(word: normalize_word(params[:word]))
|
new_word = normalize_word(params[:word])
|
||||||
|
w = WatchedWord.where("word ILIKE ?", new_word).first || WatchedWord.new(word: new_word)
|
||||||
w.action_key = params[:action_key] if params[:action_key]
|
w.action_key = params[:action_key] if params[:action_key]
|
||||||
w.action = params[:action] if params[:action]
|
w.action = params[:action] if params[:action]
|
||||||
w.save
|
w.save
|
||||||
|
|
|
@ -11,8 +11,8 @@ describe WatchedWord do
|
||||||
expect(described_class.count).to eq(1)
|
expect(described_class.count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "downcases words" do
|
it "doesn't downcase words" do
|
||||||
expect(described_class.create(word: "ShooT").word).to eq('shoot')
|
expect(described_class.create(word: "ShooT").word).to eq('ShooT')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "strips leading and trailing spaces" do
|
it "strips leading and trailing spaces" do
|
||||||
|
|
|
@ -76,6 +76,21 @@ describe WordWatcher do
|
||||||
m = WordWatcher.new("trooooooooot").word_matches_for_action?(:require_approval)
|
m = WordWatcher.new("trooooooooot").word_matches_for_action?(:require_approval)
|
||||||
expect(m[1]).to eq("trooooooooot")
|
expect(m[1]).to eq("trooooooooot")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "support uppercase" do
|
||||||
|
Fabricate(
|
||||||
|
:watched_word,
|
||||||
|
word: /a\S+ce/,
|
||||||
|
action: WatchedWord.actions[:require_approval]
|
||||||
|
)
|
||||||
|
|
||||||
|
m = WordWatcher.new('Amazing place').word_matches_for_action?(:require_approval)
|
||||||
|
expect(m).to be_nil
|
||||||
|
m = WordWatcher.new('Amazing applesauce').word_matches_for_action?(:require_approval)
|
||||||
|
expect(m[1]).to eq('applesauce')
|
||||||
|
m = WordWatcher.new('Amazing AppleSauce').word_matches_for_action?(:require_approval)
|
||||||
|
expect(m[1]).to eq('AppleSauce')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user