FIX: Do not show duplicate_link notice for quotes (#12481)

Quoting a link from the topic would show a false duplicate_link notice.
This commit is contained in:
Bianca Nenciu 2021-03-23 10:43:55 +02:00 committed by GitHub
parent bcd6efa98c
commit e48d055232
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View File

@ -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) {

View File

@ -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);
});
});