Skip to main content

html_encode

Function html_encode 

Source
pub fn html_encode(input: &str) -> String
Expand description

HTML entity encode a string

Encodes HTML special characters to their entity equivalents. This is useful for preventing XSS attacks.

§Arguments

  • input - String to HTML encode

§Example

ⓘ
let encoded = html_encode("<script>alert('xss')</script>");
assert_eq!(encoded, "&lt;script&gt;alert(&#x27;xss&#x27;)&lt;/script&gt;");