Skip to content

Sanitize Class

The Sanitize class provides HTML and XSS sanitization.

s = new Sanitize

s.html(cInput)

Sanitize HTML by stripping dangerous tags, keeping safe ones.

safe = s.html('<script>alert("xss")</script><p>Safe</p>')
# Returns: "<p>Safe</p>"

s.strict(cInput)

Strictly sanitize HTML by stripping all tags.

text = s.strict('<b>Bold</b> <script>evil()</script>')
# Returns: "Bold evil()"

s.escapeHtml(cInput)

Escape HTML special characters to entities.

escaped = s.escapeHtml('<div class="test">Hello & goodbye</div>')
# Returns: "&lt;div class=&quot;test&quot;&gt;Hello &amp; goodbye&lt;/div&gt;"