How do I handle this type of situation? I have a nodejs application with nextjs frontend. Users want to use character such as ‘&’. However I realized that after sanitizing it with this package sanitizeHtml
before storing in my database. I realized that it changes character such as “&” to ‘&’.
This is for user input. Characters coming from rich text editor are rendered well.
I wanted to prevent users from ever using “&” but I realized that they can simply copy and paste the content.
So, how do I handle this?
Here is my code:
const sanitizeText = (text)=>{
const clean = sanitizeHtml(text, {
allowedTags: [],
allowedAttributes: {},
allowedIframeHostnames: [],
allowedSchemes: [],
});
return clean;
}
is there a way I can make the character ‘&’ to be saved as ‘&’ in my database instead of the ‘&’? Or is there an efficient way to completely prevent users from using such character