Escaping and Unescaping HTML

easy
Unit 11 · Stdlib0/3 to milestone

Implement without using the html module:

  • escape(text, quote=True): replace & (first!), <, >, and when quote is true " → &quot; and ' → &#x27;
  • unescape(text): reverse those five entities plus numeric references like &#65; and &#x41;; leave unknown entities untouched

Escaping user input before inserting it into HTML is the core defence against cross-site scripting (XSS).

#security#strings2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Escaping and Unescaping HTML · TechGradify