FEATURE: Validate tags in WatchedWords (#17254)

* FEATURE: Validate tags in WatchedWords

We didn't validate watched words automatic tagging, so it was possible
for an admin to created watched words with an empty tag list which would
result in an exception when users tried to create a new topic that
matched the misconfigured watched word.

Bug report: https://meta.discourse.org/t/lib-topic-creator-fails-when-the-word-math-appears-in-the-topic-title-or-text/231018?u=falco
This commit is contained in:
Rafael dos Santos Silva
2022-06-27 16:16:33 -03:00
committed by GitHub
parent 64adf3cba3
commit f56c44d1c7
5 changed files with 29 additions and 3 deletions

View File

@ -529,11 +529,15 @@ describe PostCreator do
before do
SiteSetting.min_trust_to_create_tag = 0
SiteSetting.min_trust_level_to_tag_topics = 0
Fabricate(:tag, name: 'greetings')
Fabricate(:tag, name: 'hey')
Fabricate(:tag, name: 'about-art')
Fabricate(:tag, name: 'about-artists')
end
context "without regular expressions" do
it "works with many tags" do
Fabricate(:watched_word, action: WatchedWord.actions[:tag], word: "HELLO", replacement: "greetings , hey")
Fabricate(:watched_word, action: WatchedWord.actions[:tag], word: "HELLO", replacement: "greetings,hey")
@post = creator.create
expect(@post.topic.tags.map(&:name)).to match_array(['greetings', 'hey'])
@ -548,7 +552,7 @@ describe PostCreator do
end
it "does not treat as regular expressions" do
Fabricate(:watched_word, action: WatchedWord.actions[:tag], word: "he(llo|y)", replacement: "greetings , hey")
Fabricate(:watched_word, action: WatchedWord.actions[:tag], word: "he(llo|y)", replacement: "greetings,hey")
@post = creator_with_tags.create
expect(@post.topic.tags.map(&:name)).to match_array(tag_names)
@ -558,7 +562,7 @@ describe PostCreator do
context "with regular expressions" do
it "works" do
SiteSetting.watched_words_regular_expressions = true
Fabricate(:watched_word, action: WatchedWord.actions[:tag], word: "he(llo|y)", replacement: "greetings , hey")
Fabricate(:watched_word, action: WatchedWord.actions[:tag], word: "he(llo|y)", replacement: "greetings,hey")
@post = creator_with_tags.create
expect(@post.topic.tags.map(&:name)).to match_array(tag_names + ['greetings', 'hey'])