FIX: Do not replace in mentions and hashtags (#14260)
Watched words of type 'replace' or 'link' replaced the text inside mentions or hashtags too, which broke these. These types of watched words must skip any match that has an @ or # before it.
This commit is contained in:
parent
7b77dd5c05
commit
0532a5a43e
|
@ -119,6 +119,14 @@ export function setup(helper) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
matches[ln].index > 0 &&
|
||||||
|
(text[matches[ln].index - 1] === "@" ||
|
||||||
|
text[matches[ln].index - 1] === "#")
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (matches[ln].index > lastPos) {
|
if (matches[ln].index > lastPos) {
|
||||||
token = new state.Token("text", "", 0);
|
token = new state.Token("text", "", 0);
|
||||||
token.content = text.slice(lastPos, matches[ln].index);
|
token.content = text.slice(lastPos, matches[ln].index);
|
||||||
|
|
|
@ -1465,6 +1465,20 @@ HTML
|
||||||
expect(PrettyText.cook("f.o")).to match_html("<p>test</p>")
|
expect(PrettyText.cook("f.o")).to match_html("<p>test</p>")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not replace hashtags and mentions" do
|
||||||
|
Fabricate(:user, username: "test")
|
||||||
|
category = Fabricate(:category, slug: "test")
|
||||||
|
Fabricate(:watched_word, action: WatchedWord.actions[:replace], word: "test", replacement: "discourse")
|
||||||
|
|
||||||
|
expect(PrettyText.cook("@test #test test")).to match_html(<<~HTML)
|
||||||
|
<p>
|
||||||
|
<a class="mention" href="/u/test">@test</a>
|
||||||
|
<a class="hashtag" href="/c/test/#{category.id}">#<span>test</span></a>
|
||||||
|
discourse
|
||||||
|
</p>
|
||||||
|
HTML
|
||||||
|
end
|
||||||
|
|
||||||
it "supports overlapping words" do
|
it "supports overlapping words" do
|
||||||
Fabricate(:watched_word, action: WatchedWord.actions[:link], word: "meta", replacement: "https://meta.discourse.org")
|
Fabricate(:watched_word, action: WatchedWord.actions[:link], word: "meta", replacement: "https://meta.discourse.org")
|
||||||
Fabricate(:watched_word, action: WatchedWord.actions[:replace], word: "iz", replacement: "is")
|
Fabricate(:watched_word, action: WatchedWord.actions[:replace], word: "iz", replacement: "is")
|
||||||
|
|
Loading…
Reference in New Issue