From 385a4d034f05ad828d9ef398c479ba196c6f8cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 23 Jan 2026 19:55:56 -0500 Subject: [PATCH] fix: #10682, fix all the other rss routes as well --- public/src/utils.common.js | 2 +- src/routes/feeds.js | 41 ++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/public/src/utils.common.js b/public/src/utils.common.js index a35c6a2ea0..fbebb7ba73 100644 --- a/public/src/utils.common.js +++ b/public/src/utils.common.js @@ -310,7 +310,7 @@ const utils = { tag = tag.trim().toLowerCase(); // see https://github.com/NodeBB/NodeBB/issues/4378 - tag = tag.replace(/\u202E/gi, ''); + tag = utils.stripBidiControls(tag); tag = tag.replace(/[,/#!$^*;:{}=_`<>'"~()?|]/g, ''); tag = tag.slice(0, maxLength || 15).trim(); const matches = tag.match(/^[.-]*(.+?)[.-]*$/); diff --git a/src/routes/feeds.js b/src/routes/feeds.js index 3d680fe85f..0e4c066673 100644 --- a/src/routes/feeds.js +++ b/src/routes/feeds.js @@ -263,7 +263,7 @@ async function generateTopicsFeed(feedOptions, feedTopics, timestampField) { feedOptions.feed_url = nconf.get('url') + feedOptions.feed_url; feedOptions.site_url = nconf.get('url') + feedOptions.site_url; - feedTopics = feedTopics.filter(Boolean); + feedTopics = feedTopics.filter(t => t && !t.deleted); const feed = new rss(feedOptions); @@ -271,38 +271,39 @@ async function generateTopicsFeed(feedOptions, feedTopics, timestampField) { feed.pubDate = new Date(feedTopics[0][timestampField]).toUTCString(); } - async function addFeedItem(topicData) { + if (feedOptions.useMainPost) { + const tids = feedTopics.map(topic => topic.tid); + const mainPosts = await topics.getMainPosts(tids, feedOptions.uid); + feedTopics.forEach((topicData, index) => { + topicData.mainPost = mainPosts[index]; + }); + } + + function addFeedItem(topicData) { + const title = stripUnicodeControlChars(topicData.title); const feedItem = { - title: utils.stripHTMLTags(topicData.title, utils.tags), + title: utils.stripHTMLTags(title, utils.tags), url: `${nconf.get('url')}/topic/${topicData.slug}`, date: new Date(topicData[timestampField]).toUTCString(), }; - if (topicData.deleted) { - return; - } - if (topicData.teaser && topicData.teaser.user && !feedOptions.useMainPost) { - feedItem.description = topicData.teaser.content; + feedItem.description = stripUnicodeControlChars(topicData.teaser.content); feedItem.author = topicData.teaser.user.username; feed.item(feedItem); return; } - - const mainPost = await topics.getMainPost(topicData.tid, feedOptions.uid); + const { mainPost } = topicData; if (!mainPost) { feed.item(feedItem); return; } - feedItem.description = mainPost.content; + feedItem.description = stripUnicodeControlChars(mainPost.content); feedItem.author = mainPost.user && mainPost.user.username; feed.item(feedItem); } - for (const topicData of feedTopics) { - /* eslint-disable no-await-in-loop */ - await addFeedItem(topicData); - } + feedTopics.forEach(addFeedItem); return feed; } @@ -368,9 +369,10 @@ function generateForPostsFeed(feedOptions, posts) { } posts.forEach((postData) => { + const title = stripUnicodeControlChars(postData.topic ? postData.topic.title : ''); feed.item({ - title: postData.topic ? postData.topic.title : '', - description: postData.content, + title: title, + description: stripUnicodeControlChars(postData.content), url: `${nconf.get('url')}/post/${postData.pid}`, author: postData.user ? postData.user.username : '', date: new Date(parseInt(postData.timestamp, 10)).toUTCString(), @@ -405,7 +407,8 @@ async function generateForTag(req, res) { return controllers404.handle404(req, res); } const uid = await getUidFromToken(req); - const tag = validator.escape(String(req.params.tag)); + const set = `tag:${String(req.params.tag)}:topics`; + const tag = validator.escape(stripUnicodeControlChars(String(req.params.tag))); const page = parseInt(req.query.page, 10) || 1; const topicsPerPage = meta.config.topicsPerPage || 20; const start = Math.max(0, (page - 1) * topicsPerPage); @@ -418,7 +421,7 @@ async function generateForTag(req, res) { site_url: `/tags/${tag}`, start: start, stop: stop, - }, `tag:${tag}:topics`, res); + }, set, res); } async function getUidFromToken(req) {