Skip to content

Commit

Permalink
FIX: Do not show duplicate_link notice for quotes (#12481)
Browse files Browse the repository at this point in the history
Quoting a link from the topic would show a false duplicate_link notice.
  • Loading branch information
nbianca committed Mar 23, 2021
1 parent bcd6efa commit e48d055
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/assets/javascripts/discourse/app/controllers/composer.js
Expand Up @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions app/assets/javascripts/discourse/tests/acceptance/composer-test.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
});

0 comments on commit e48d055

Please sign in to comment.