Watched words links corrupt @mentions and #categories

AI-generated summary

The discussion highlights a bug where Discourse’s core Watched Words feature incorrectly converts @mentions, categories, and tags into links when they contain watched words — breaking intended functionality. nathank reports this issue after migrating from @sam’s theme component, which handled such cases more intelligently. sam acknowledges the problem, noting that symbols like @ and # should be treated as part of the word (e.g., discourseconnect should not be auto-linked). Simon_Manning suggests the safest fix: prioritize @mentions, categories, and tags over watched word replacements — allowing overlaps to remain functional unless the text doesn’t match a mention/category/tag (e.g., #NotACategoryOrTag). The issue was resolved by nbianca, who notes that since PR #14260 was merged, words preceded by @ or # are no longer replaced by watched word links, preserving their intended behavior. This fix aligns with the original theme component’s logic and ensures mentions, categories, and tags remain unaffected by watched word rules.

I’ve just converted from @sam’s great Auto-Linkify Words theme component to the fairly new core Watched Words.

Unfortunately, this has broken any @mentions, categories, and tags that happen to contain a Watched Word in the posts on our forum. There are quite a lot of these.

The Theme Component had pretty good logic for this - could this aspect also be incorporated into the core functionality?

4 Likes

I see, yes something is not feeling right here, @nbianca can probably have a look in a week or so.

We have DiscourseConnect → https://meta.discourse.org/t/13045

I guess the gap here is that @ and # should be treated as part of the word and discourseconnect should not be auto linked?

4 Likes

If reasonably possible, the safest behaviour would seem to me to be only applying a watched words match if an @mentions, categories or tags match has not already been made.

That would allow mention/category/tag links to be used where watched words happen to overlap while also still allowing watched words to catch something in e.g. #NotACategoryOrTag

1 Like

Words preceded by # or @ will no longer be replaced by other words or links since this PR was merged:

https://github.com/discourse/discourse/pull/14260

4 Likes