Skip to content

Node.js based forum software built for the modern web

fix: #12732 editing of remote post content

Julian Lam25bf97ae2893
diff --git a/src/api/posts.js b/src/api/posts.js
index 5d5a7742a1..259fcf6407 100644
--- a/src/api/posts.js
+++ b/src/api/posts.js
@@ -90,17 +90,25 @@ postsAPI.edit = async function (caller, data) {
if (!caller.uid) {
throw new Error('[[error:not-logged-in]]');
}
- // Trim and remove HTML (latter for composers that send in HTML, like redactor)
- const contentLen = utils.stripHTMLTags(data.content).trim().length;
+
+ // Discard content for non-local posts
+ if (!utils.isNumber(data.pid)) {
+ data.content = null;
+ } else {
+ // Trim and remove HTML (latter for composers that send in HTML, like redactor)
+ const contentLen = utils.stripHTMLTags(data.content).trim().length;
+
+ if (meta.config.minimumPostLength !== 0 && contentLen < meta.config.minimumPostLength) {
+ throw new Error(`[[error:content-too-short, ${meta.config.minimumPostLength}]]`);
+ } else if (contentLen > meta.config.maximumPostLength) {
+ throw new Error(`[[error:content-too-long, ${meta.config.maximumPostLength}]]`);
+ }
+ }
if (data.title && data.title.length < meta.config.minimumTitleLength) {
throw new Error(`[[error:title-too-short, ${meta.config.minimumTitleLength}]]`);
} else if (data.title && data.title.length > meta.config.maximumTitleLength) {
throw new Error(`[[error:title-too-long, ${meta.config.maximumTitleLength}]]`);
- } else if (meta.config.minimumPostLength !== 0 && contentLen < meta.config.minimumPostLength) {
- throw new Error(`[[error:content-too-short, ${meta.config.minimumPostLength}]]`);
- } else if (contentLen > meta.config.maximumPostLength) {
- throw new Error(`[[error:content-too-long, ${meta.config.maximumPostLength}]]`);
} else if (!await posts.canUserPostContentWithLinks(caller.uid, data.content)) {
throw new Error(`[[error:not-enough-reputation-to-post-links, ${meta.config['min:rep:post-links']}]]`);
}
diff --git a/src/posts/edit.js b/src/posts/edit.js
index a8b702232e..610a659e4f 100644
--- a/src/posts/edit.js
+++ b/src/posts/edit.js
@@ -34,6 +34,7 @@ module.exports = function (Posts) {
await scheduledTopicCheck(data, topicData);
+ data.content = data.content === null ? postData.content : data.content;
const oldContent = postData.content; // for diffing purposes
const editPostData = getEditPostData(data, topicData, postData);
@@ -106,7 +107,7 @@ module.exports = function (Posts) {
const { tid } = postData;
const title = data.title ? data.title.trim() : '';
- const isMain = parseInt(data.pid, 10) === parseInt(topicData.mainPid, 10);
+ const isMain = String(data.pid) === String(topicData.mainPid);
if (!isMain) {
return {
tid: tid,