From 09967a0be9453e8f2baedf5e84bb4730ee710c18 Mon Sep 17 00:00:00 2001 From: deadvey Date: Sun, 7 Sep 2025 22:11:58 +0100 Subject: [PATCH] Automatically removes leading and trailing spaces from tags because tags are often entered with a space after each comma. This uses .trim() in func.render_tags() to remove when rendering as well as .map(str => str.trim()) when a post or post edit is submitted so they are also stored without spaces. --- src/functions.js | 2 +- src/server.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/functions.js b/src/functions.js index f86bff1..c4762c3 100644 --- a/src/functions.js +++ b/src/functions.js @@ -44,7 +44,7 @@ export function render_tags(tags) { } else { for (let tag_index = 0; tag_index < tags.length; tag_index++) { // Loop over each tag - string += `${tags[tag_index]}` // Adds the tag to the string as a HTML href + string += `${tags[tag_index].trim()}` // Adds the tag to the string as a HTML href if (tag_index < tags.length - 1) { // If there are more tags, then insert a comma string += ", "; } diff --git a/src/server.js b/src/server.js index ed11d22..dd34430 100644 --- a/src/server.js +++ b/src/server.js @@ -360,7 +360,7 @@ app.post("/submit_post", (req,res) => { const username = func.escape_input(req.body.username) const title = func.escape_input(req.body.title) const content = req.body.content - const tags = func.escape_input(req.body.tags).split(','); + const tags = func.escape_input(req.body.tags).split(',').map(str => str.trim()); const unix_timestamp = getUnixTime(new Date()) if (func.get_userID(username) == -1) { @@ -486,7 +486,7 @@ app.post("/submit_edit_post", (req,res) => { const userID = req.body.userID const title = func.escape_input(req.body.title) const content = req.body.content - const tags = func.escape_input(req.body.tags).split(",") + const tags = func.escape_input(req.body.tags).split(",").map(str => str.trim()); const delete_bool = req.body.delete const unix_timestamp = getUnixTime(new Date()) console.log(users[userID]['prettyname'], "is editting the post titled:", title);