Fixed a bug where comments could be submitted without any content

and where the hitcount was incremented before the program checked if
the post existed
This commit is contained in:
deadvey
2025-10-24 13:05:31 +01:00
parent 4ad7352fcc
commit 2d33ce79a8
4 changed files with 26 additions and 15 deletions

View File

@@ -19,21 +19,25 @@ router.post("/submit_comment", (req,res) => {
const postID = parseInt(req.body.post_index)
const content = func.escape_input(req.body.content)
let name = func.escape_input(req.body.name)
if (name == "") {
// Give the user the default username if they left that bit blank
if (name == "" || typeof name == 'undefined') {
name = config.default_commenter_username
}
let comments = data.getdata('comments')
// Check there is actually content in the comment
if (content != '' && typeof content != 'undefined') {
let comments = data.getdata('comments')
new_comment = {
"name": name,
"content": content,
"id": comments[postID].length,
"pubdate": unix_timestamp,
"postID": postID,
};
comments[postID].push(new_comment);
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
new_comment = {
"name": name,
"content": content,
"id": comments[postID].length,
"pubdate": unix_timestamp,
"postID": postID,
};
comments[postID].push(new_comment);
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
}
res.redirect(301,`/post/${req.body.post_index}`)
}); // /submit_comment