I'm experiencing an issue that is causing me more trouble than I would expect it to. I have created a blog site which involves taking a user's post and sanitizing the content that is sent. To sanitize the data I use express-validator's body.escape() method, and it is doing it's job. My issue is with the display of the data when it is retrieved and served on the webpage - the content is still escaped when it is displayed (i.e., instead of displaying an apostrophe, it displays "& #x27;". This seems like it would be a common problem with readily available solutions, but I can't seem to figure out how to easily unescape the content to deliver it to the user.
The function which displays the blog posts to the users is:
exports.index = function (req, res, next) {
Post.find({}, "title content date tags formatted_date")
.sort({ date: -1 })
.populate("tags")
.exec(function (err, list_posts) {
if (err) {
return next(err);
}
//Successful, so render
res.render("index", {
title: `Blog Site`,
post_list: list_posts,
user: req.user,
home: true,
});
});
};
Any guidance here would be highly appreciated. I would like to unescape list_posts.content.