FIX: Do not replace hashtag-cooked text with WatchedWords (#19279)

Adds the .hashtag-cooked as an exception for watched
words to not auto-link the text of the hashtag.
This commit is contained in:
Martin Brennan 2022-12-01 16:31:06 +10:00 committed by GitHub
parent fb2507c6ce
commit 30e7b716b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -107,7 +107,10 @@ export function setup(helper) {
currentToken.type === "span_open") &&
currentToken.attrs &&
currentToken.attrs.some(
(attr) => attr[0] === "class" && attr[1] === "hashtag"
(attr) =>
attr[0] === "class" &&
(attr[1].includes("hashtag") ||
attr[1].includes("hashtag-cooked"))
)
) {
lastType =

View File

@ -1690,7 +1690,7 @@ HTML
SiteSetting.watched_words_regular_expressions = true
Fabricate(:user, username: "test")
category = Fabricate(:category, slug: "test")
category = Fabricate(:category, slug: "test", name: "test")
Fabricate(:watched_word, action: WatchedWord.actions[:replace], word: "es", replacement: "discourse")
expect(PrettyText.cook("@test #test test")).to match_html(<<~HTML)
@ -1700,6 +1700,15 @@ HTML
tdiscourset
</p>
HTML
SiteSetting.enable_experimental_hashtag_autocomplete = true
expect(PrettyText.cook("@test #test test")).to match_html(<<~HTML)
<p>
<a class="mention" href="/u/test">@test</a>
<a class="hashtag-cooked" href="#{category.url}" data-type="category" data-slug="test"><svg class="fa d-icon d-icon-folder svg-icon svg-node"><use href="#folder"></use></svg><span>test</span></a>
tdiscourset
</p>
HTML
end
it "supports overlapping words" do