Skip to content

Node.js based forum software built for the modern web

fix: revert introduction of toPid into post intFields, manually cast toPid as int in getPostSummaryByPids if present and numeric

Julian Lam3a870360c49e
diff --git a/src/posts/data.js b/src/posts/data.js
index 20f1df2991..8edd4096e6 100644
--- a/src/posts/data.js
+++ b/src/posts/data.js
@@ -8,7 +8,7 @@ const activitypub = require('../activitypub');
const utils = require('../utils');
const intFields = [
- 'uid', 'pid', 'tid', 'toPid', 'deleted', 'timestamp',
+ 'uid', 'pid', 'tid', 'deleted', 'timestamp',
'upvotes', 'downvotes', 'deleterUid', 'edited',
'replies', 'bookmarks',
];
@@ -62,7 +62,7 @@ function modifyPost(post, fields) {
const _intFields = [...intFields];
if (post) {
- ['pid', 'uid', 'tid', 'toPid'].forEach((prop) => {
+ ['pid', 'uid', 'tid'].forEach((prop) => {
if (
post.hasOwnProperty(prop) &&
(activitypub.helpers.isUri(post[prop]) || validator.isUUID(String(post[prop])))
diff --git a/src/posts/summary.js b/src/posts/summary.js
index a07b8e2c67..6865372cef 100644
--- a/src/posts/summary.js
+++ b/src/posts/summary.js
@@ -44,6 +44,10 @@ module.exports = function (Posts) {
if (!uidToUser.hasOwnProperty(post.uid)) {
post.uid = 0;
}
+
+ // toPid is nullable so it is casted separately
+ post.toPid = utils.isNumber(post.toPid) ? parseInt(post.toPid, 10) : post.toPid;
+
post.user = uidToUser[post.uid];
Posts.overrideGuestHandle(post, post.handle);
post.handle = undefined;