escapeHtml
Escapes the HTML special characters &, <, >, ", and ' in a string.
Use this to safely embed untrusted content into HTML attribute values or text nodes without risk of XSS injection.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
str | string | The string to escape. |
Returns
Section titled “Returns”string — The escaped string.
Examples
Section titled “Examples”Escape script tags
Section titled “Escape script tags”Converts < > ” ’ & to their HTML entities to prevent XSS.
Safe interpolation in templates
Section titled “Safe interpolation in templates”Safe for inserting untrusted strings into HTML.
