posts: update post body checks and regex

This commit is contained in:
Jonathan Barrow
2024-02-28 19:04:12 -05:00
parent 24dddb2062
commit e3736862ca
3 changed files with 19 additions and 10 deletions

View File

@@ -97,13 +97,17 @@ router.post('/new', async function (req, res, next) {
miiFace = 'normal_face.png';
break;
}
let body = req.body.body;
if (body) {
body = req.body.body.replace(/[^\p{L}\p{P}\d\n\r~$^¨←→↑↓√¦⇒⇔¤¢€£¥™©®+×÷=±∞˘˙¸˛˜°¹²³♭♪¬¯¼½¾♡♥●◆■▲▼☆★♀♂<>]/gu, '');
const body = req.body.body;
if (body && util.INVALID_POST_BODY_REGEX.test(body)) {
// TODO - Log this error
return res.sendStatus(422);
}
if (body.length > 280) {
body = body.substring(0,280);
if (body && body.length > 280) {
// TODO - Log this error
return res.sendStatus(422);
}
const document = {
community_id: conversation.id,
screen_name: req.user.mii.name,

View File

@@ -240,12 +240,15 @@ async function newPost(req, res) {
miiFace = 'normal_face.png';
break;
}
let body = req.body.body;
if (body) {
body = req.body.body.replace(/[^\p{L}\p{P}\d\n\r~$^¨←→↑↓√¦⇒⇔¤¢€£¥™©®+×÷=±∞˘˙¸˛˜°¹²³♭♪¬¯¼½¾♡♥●◆■▲▼☆★♀♂<>]/gu, '');
const body = req.body.body;
if (body && util.INVALID_POST_BODY_REGEX.test(body)) {
// TODO - Log this error
return res.sendStatus(422);
}
if (body.length > 280 && !req.moderator) {
body = body.substring(0, 280);
if (body && body.length > 280) {
// TODO - Log this error
return res.sendStatus(422);
}
const document = {
title_id: community.title_id[0],

View File

@@ -74,6 +74,8 @@ function nameCache() {
}
const methods = {
// TODO - This doesn't belong here, just hacking it in. Gonna redo this whole server anyway so fuck it
INVALID_POST_BODY_REGEX: /[^\p{L}\p{P}\d\n\r$^¨←→↑↓√¦⇒⇔¤¢€£¥™©®+×÷=±∞˘˙¸˛˜°¹²³♭♪¬¯¼½¾♡♥●◆■▲▼☆★♀♂<> ]/gu,
create_user: async function(pid, experience, notifications) {
const pnid = await this.getUserDataFromPid(pid);
if (!pnid) {