FIX: Do not perform link lookup for replaced links (#14742)

FIX: Do not perform link lookup for replaced links (#14742)

A link that was added because a watched word was replaced could create a notice if the same link was present before.

diff --git a/app/assets/javascripts/discourse/app/controllers/composer.js b/app/assets/javascripts/discourse/app/controllers/composer.js
index 479b702..ce6bde3 100644
--- a/app/assets/javascripts/discourse/app/controllers/composer.js
+++ b/app/assets/javascripts/discourse/app/controllers/composer.js
@@ -505,6 +505,11 @@ export default Controller.extend({
       $links.each((idx, l) => {
         const href = l.href;
         if (href && href.length) {
+          // skip links added by watched words
+          if (l.dataset.word !== undefined) {
+            return true;
+          }
+
           // skip links in quotes and oneboxes
           for (let element = l; element; element = element.parentElement) {
             if (
diff --git a/app/assets/javascripts/pretty-text/addon/allow-lister.js b/app/assets/javascripts/pretty-text/addon/allow-lister.js
index 0420044..a6378ee 100644
--- a/app/assets/javascripts/pretty-text/addon/allow-lister.js
+++ b/app/assets/javascripts/pretty-text/addon/allow-lister.js
@@ -139,6 +139,7 @@ export const DEFAULT_LIST = [
   `a.inline-onebox`,
   `a.inline-onebox-loading`,
   "a[data-bbcode]",
+  "a[data-word]",
   "a[name]",
   "a[rel=nofollow]",
   "a[rel=ugc]",
diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js
index ec7f26f..2bcffba 100644
--- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js
+++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js
@@ -32,6 +32,8 @@ function findAllMatches(text, matchers) {
 }
 
 export function setup(helper) {
+  const opts = helper.getOptions();
+
   helper.registerPlugin((md) => {
     const matchers = [];
 
@@ -139,6 +141,9 @@ export function setup(helper) {
                 if (htmlLinkLevel === 0 && state.md.validateLink(url)) {
                   token = new state.Token("link_open", "a", 1);
                   token.attrs = [["href", url]];
+                  if (opts.discourse.previewing) {
+                    token.attrs.push(["data-word", ""]);
+                  }
                   token.level = level++;
                   token.markup = "linkify";
                   token.info = "auto";

GitHub sha: 148ee1d1627cda7d65a028bf43f548e1b3efed6a

This commit appears in #14742 which was approved by eviltrout. It was merged by nbianca.