I am writing an application where the user can add messages, they are saved in the firebase, and displayed on the page. I am using the following method to protect html injection:
function testHtml(str){
return str.replace(/</g, '<').replace(/>/g, '>');
}
And I output the text as follows:
$("#save").click(function(){
let text = $("#text").val(); //user input
text = testHtml(text);
$("#resultDiv").append(text);
});
I want to know if this method is safe? Are there any workarounds? If so, which ones? I use this filtering method when displaying messages. Many thanks for considering my request.