From d3c5a79d44fe443cd5a67ced3d98adfb43f57324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 1 Jun 2023 13:48:12 -0400 Subject: [PATCH] fix: #11664, dont create backlinks for quotes --- src/topics/posts.js | 7 ++++++- test/posts.js | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/topics/posts.js b/src/topics/posts.js index fcc4355bdf..84bdc4220c 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -373,8 +373,13 @@ module.exports = function (Topics) { throw new Error('[[error:invalid-data]]'); } + + let { content } = postData; + // ignore lines that start with `>` + content = content.split('\n').filter(line => !line.trim().startsWith('>')).join('\n'); // Scan post content for topic links - const matches = [...postData.content.matchAll(backlinkRegex)]; + const matches = [...content.matchAll(backlinkRegex)]; + console.log('match', matches); if (!matches) { return 0; } diff --git a/test/posts.js b/test/posts.js index 3adedb766b..866fc3b529 100644 --- a/test/posts.js +++ b/test/posts.js @@ -1163,6 +1163,28 @@ describe('Post\'s', () => { assert(backlinks); assert.strictEqual(backlinks.length, 0); }); + + it('should not detect backlinks if they are in quotes', async () => { + const content = ` + @baris said in [ok testing backlinks](/post/32145): + > here is a back link to a topic + > + > + > This is a link to [topic 1](${nconf.get('url')}/topic/1/abcdef + + This should not generate backlink + `; + const count = await topics.syncBacklinks({ + pid: 2, + content: content, + }); + + const backlinks = await db.getSortedSetMembers('pid:2:backlinks'); + + assert.strictEqual(count, 0); + assert(backlinks); + assert.strictEqual(backlinks.length, 0); + }); }); describe('integration tests', () => {