JSFiddle - React, Tailwind, and code Playground
by Ishank Dubey
HTML
<!-- Note: &nbsp; is used to make sure that the value of the input is instead of a space. -->
<form id="form">
<input type="text" id="input" placeholder="input" value="Entity:& >
Bad attempt at XSS:<script>alert('new\nline?')</script><br>">
<input type="submit" value="alert(input)">
In the above example, "&nbsp;" should be replaced with a space, and the rest of the text should be displayed as-is. See http://stackoverflow.com/a/7394787/938089.
</form>
CSS
input {
width: 100%;
display: block;
}
JavaScript
function decodeHtml(html) {
var txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
document.getElementById('form').onsubmit = function(e) {
e.preventDefault();
var input = document.getElementById('input').value;
var output = decodeHtml(input);
alert(output);
}