From 57a7c698fcef24794c6817bee0aaf794aa5f0849 Mon Sep 17 00:00:00 2001 From: CaramelKat <32065563+caramelkat@users.noreply.github.com> Date: Mon, 3 Oct 2022 21:30:26 -0500 Subject: [PATCH] Added filter to prevent invalid characters from showing up in the body of API responses --- src/util/CommunityPostGen.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/CommunityPostGen.js b/src/util/CommunityPostGen.js index f28fa2c..7565c59 100644 --- a/src/util/CommunityPostGen.js +++ b/src/util/CommunityPostGen.js @@ -16,7 +16,7 @@ class CommunityPostGen { for (let i = 0; i < posts.length; i++) { xml = xml.e("post") .e("app_data", posts[i].app_data).up() - .e("body", posts[i].body).up() + .e("body", posts[i].body.replace(/[^A-Za-z\d\s-_!@#$%^&*(){}+=,.<>/?;:'"\[\]]/g, "")).up() .e("community_id", community.id).up() .e("country_id", "254").up() .e("created_at", moment(posts[i].created_at).format("YYYY-MM-DD hh:mm:ss")).up() @@ -61,7 +61,7 @@ class CommunityPostGen { for (let i = 0; i < posts.length; i++) { xml = xml.e("post") .e("app_data", posts[i].app_data).up() - .e("body", posts[i].body).up() + .e("body", posts[i].body.replace(/[^A-Za-z\d\s-_!@#$%^&*(){}+=,.<>/?;:'"\[\]]/g, "")).up() .e("community_id", community.community_id).up() .e("country_id", "254").up() .e("created_at", moment(posts[i].created_at).format('YYYY-MM-DD HH:MM:SS')).up() @@ -154,7 +154,7 @@ class CommunityPostGen { if (post.app_data) { xml = xml.e("app_data", post.app_data).up(); } - xml = xml.e("body", post.body).up() + xml = xml.e("body", post.body.replace(/[^A-Za-z\d\s-_!@#$%^&*(){}+=,.<>/?;:'"\[\]]/g, "")).up() .e("community_id", post.community_id).up() .e("country_id", "254").up() .e("created_at", post.created_at).up() @@ -213,7 +213,7 @@ class CommunityPostGen { for (const post of posts) { let newBody = ''; if(post.body) - newBody = post.body.replace( /[\r\n]+/gm, ''); + newBody = post.body.replace(/[^A-Za-z\d\s-_!@#$%^&*(){}+=,.<>/?;:'"\[\]]/g, ""); xml = xml.e("person") .e("posts") .e("post")