mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Add word boundaries to replace and tag watched words (#13405)
The generated regular expressions did not contain \b which matched every text that contained the word, even if it was only a substring of a word. For example, if "art" was a watched word a post containing word "artist" matched.
This commit is contained in:
@@ -502,13 +502,21 @@ describe PostCreator do
|
||||
end
|
||||
|
||||
context "without regular expressions" do
|
||||
it "works" do
|
||||
it "works with many tags" do
|
||||
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'])
|
||||
end
|
||||
|
||||
it "works with overlapping words" do
|
||||
Fabricate(:watched_word, action: WatchedWord.actions[:tag], word: "art", replacement: "about-art")
|
||||
Fabricate(:watched_word, action: WatchedWord.actions[:tag], word: "artist*", replacement: "about-artists")
|
||||
|
||||
post = PostCreator.new(user, title: "hello world topic", raw: "this is topic abour artists", archetype_id: 1).create
|
||||
expect(post.topic.tags.map(&:name)).to match_array(['about-artists'])
|
||||
end
|
||||
|
||||
it "does not treat as regular expressions" do
|
||||
Fabricate(:watched_word, action: WatchedWord.actions[:tag], word: "he(llo|y)", replacement: "greetings , hey")
|
||||
|
||||
|
||||
@@ -1420,6 +1420,10 @@ HTML
|
||||
expect(PrettyText.cook("Lorem ipsum dolor sittt amet")).to match_html(<<~HTML)
|
||||
<p>Lorem ipsum something else amet</p>
|
||||
HTML
|
||||
|
||||
expect(PrettyText.cook("Lorem ipsum xdolor sit amet")).to match_html(<<~HTML)
|
||||
<p>Lorem ipsum xdolor sit amet</p>
|
||||
HTML
|
||||
end
|
||||
|
||||
it "replaces words with links" do
|
||||
|
||||
Reference in New Issue
Block a user