I'm creating a web using nodejs, ExpressJS, EJS
and MySQL
.
I save some data with HTML
code in MySQL
.
When I get data from MySQL
and show in web,an error occur: HTML tag in data also showing with data.
How can you help me solve this problem.
Thanks.
Try to pass your output through a function such as:
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
Shamelessly copied from here.