fix: #14147, dont create wrong backlinks

syncBacklinks expects raw post content, html was passed to it from onNewPost since it was switched to use getPostSummary
backlinkRegex was matching  ${nconf.get('url')}/topic/1aef954c-d0dc-45cf-acf2-e3a59f6cc134/foo and return tid=1 instead of the uuid

remove useless if check in syncBacklinks
fixed parseInts on tids
current - remove are both arrays use .length
This commit is contained in:
Barış Soner Uşaklı
2026-04-03 21:54:05 -04:00
parent e145330c37
commit a09192d486
3 changed files with 28 additions and 23 deletions

View File

@@ -1152,12 +1152,10 @@ describe('Post\'s', () => {
describe('.syncBacklinks()', () => {
it('should error on invalid data', async () => {
try {
await topics.syncBacklinks();
} catch (e) {
assert(e);
assert.strictEqual(e.message, '[[error:invalid-data]]');
}
await assert.rejects(
topics.syncBacklinks(),
{ message: '[[error:invalid-data]]' },
);
});
it('should do nothing if the post does not contain a link to a topic', async () => {
@@ -1192,9 +1190,7 @@ describe('Post\'s', () => {
const backlinks = await db.getSortedSetMembers('pid:2:backlinks');
assert.strictEqual(count, 0);
assert(events);
assert.strictEqual(events.length, 1);
assert(backlinks);
assert.strictEqual(backlinks.length, 0);
});
@@ -1219,6 +1215,17 @@ describe('Post\'s', () => {
assert(backlinks);
assert.strictEqual(backlinks.length, 0);
});
it('should not create a wrong backlink to topic/1 with AP topic url', async () => {
const { postData } = await topics.post({
uid: 1,
cid,
title: 'Topic backlink testing - topic 2',
content: `testing ${nconf.get('url')}/topic/1aef954c-d0dc-45cf-acf2-e3a59f6cc134/foo`,
});
const backlinks = await db.getSortedSetMembers(`pid:${postData.pid}:backlinks`);
assert.strictEqual(backlinks.length, 0);
});
});
describe('integration tests', () => {