diff --git a/app/assets/javascripts/discourse/app/controllers/composer.js b/app/assets/javascripts/discourse/app/controllers/composer.js index 842fc6ac2aa..f50deaaeb0a 100644 --- a/app/assets/javascripts/discourse/app/controllers/composer.js +++ b/app/assets/javascripts/discourse/app/controllers/composer.js @@ -453,8 +453,25 @@ export default Controller.extend({ const post = this.get("model.post"); const $links = $("a[href]", $preview); $links.each((idx, l) => { - const href = $(l).prop("href"); + const href = l.href; if (href && href.length) { + // skip links in quotes + for (let element = l; element; element = element.parentElement) { + if ( + element.tagName === "DIV" && + element.classList.contains("d-editor-preview") + ) { + break; + } + + if ( + element.tagName === "ASIDE" && + element.classList.contains("quote") + ) { + return true; + } + } + const [warn, info] = linkLookup.check(post, href); if (warn) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js index 164750ee135..09eea43465b 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js @@ -14,6 +14,7 @@ import { run } from "@ember/runloop"; import selectKit from "discourse/tests/helpers/select-kit-helper"; import sinon from "sinon"; import { toggleCheckDraftPopup } from "discourse/controllers/composer"; +import LinkLookup from "discourse/lib/link-lookup"; acceptance("Composer", function (needs) { needs.user(); @@ -934,4 +935,30 @@ acceptance("Composer", function (needs) { "it does not unescapes script tags in code blocks" ); }); + + test("Shows duplicate_link notice", async function (assert) { + await visit("/t/internationalization-localization/280"); + await click("#topic-footer-buttons .create"); + + this.container.lookup("controller:composer").set( + "linkLookup", + new LinkLookup({ + "github.com": { + domain: "github.com", + username: "system", + posted_at: "2021-01-01T12:00:00.000Z", + post_number: 1, + }, + }) + ); + + await fillIn(".d-editor-input", "[](https://discourse.org)"); + assert.equal(find(".composer-popup").length, 0); + + await fillIn(".d-editor-input", "[quote][](https://github.com)[/quote]"); + assert.equal(find(".composer-popup").length, 0); + + await fillIn(".d-editor-input", "[](https://github.com)"); + assert.equal(find(".composer-popup").length, 1); + }); });