Hashing, encoding and basic security · 13 / 15 Exercise Medium

Escape HTML against injections

Objective

If you insert a user's text into an HTML page without escaping it, that text can contain tags or scripts (XSS injection). html.escape converts dangerous characters into entities and html.unescape does the opposite.

Instructions

  • The first line has the number n of lines; each one is esc text or unesc text, with the text as the rest of the line.
  • For esc show the escaped text inside a paragraph: <p>...</p>. For unesc show the original text.
Input
2
esc <b>hola</b>
unesc &lt;i&gt;
Output
<p>&lt;b&gt;hola&lt;/b&gt;</p>
<i>

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise