From 2408ecd8dc325e266e951e59cc54f75e94dd6562 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 21 Mar 2024 00:41:53 -0400 Subject: [PATCH] fix: post urls to use prefix instead of linking out directly to origin server, exposed encodeURIComponent as a template helper for themes --- public/src/modules/helpers.common.js | 9 +++++++-- src/activitypub/inbox.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js index 820b0c09b3..b426fdaf51 100644 --- a/public/src/modules/helpers.common.js +++ b/public/src/modules/helpers.common.js @@ -27,6 +27,7 @@ module.exports = function (utils, Benchpress, relative_path) { increment, generateRepliedTo, generateWrote, + encodeURIComponent: _encodeURIComponent, isoTimeToLocaleString, shouldHideReplyContainer, humanReadableNumber, @@ -340,13 +341,17 @@ module.exports = function (utils, Benchpress, relative_path) { post.parent.displayname : '[[global:guest]]'; const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs)); const langSuffix = isBeforeCutoff ? 'on' : 'ago'; - return `[[topic:replied-to-user-${langSuffix}, ${post.toPid}, ${relative_path}/post/${post.toPid}, ${displayname}, ${relative_path}/post/${post.pid}, ${post.timestampISO}]]`; + return `[[topic:replied-to-user-${langSuffix}, ${post.toPid}, ${relative_path}/post/${encodeURIComponent(post.toPid)}, ${displayname}, ${relative_path}/post/${encodeURIComponent(post.pid)}, ${post.timestampISO}]]`; } function generateWrote(post, timeagoCutoff) { const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs)); const langSuffix = isBeforeCutoff ? 'on' : 'ago'; - return `[[topic:wrote-${langSuffix}, ${relative_path}/post/${post.pid}, ${post.timestampISO}]]`; + return `[[topic:wrote-${langSuffix}, ${relative_path}/post/${encodeURIComponent(post.pid)}, ${post.timestampISO}]]`; + } + + function _encodeURIComponent(value) { + return encodeURIComponent(value); } function isoTimeToLocaleString(isoTime, locale = 'en-GB') { diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index 49c50f4ab1..e224ab1599 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -154,7 +154,7 @@ inbox.announce = async (req) => { await topics.events.log(tid, { type: 'announce', uid: actor, - href: `/post/${pid}`, + href: `/post/${encodeURIComponent(pid)}`, pid, timestamp, });