pub fn html_entity_encode(input: &str) -> StringExpand description
Encodes text using various HTML entity formats.
Randomly encodes characters using plain text, decimal entities (&#...;),
hexadecimal entities (&#x...;), or named entities (<, >, etc.).
This mixed approach tests HTML parser robustness and can bypass filters.
§Use Cases
- XSS Testing: Bypass HTML sanitizers with entity encoding
- Red Team: Evade WAF rules that look for literal characters
- Blue Team: Test HTML entity decoder implementations
- Web Scraping: Handle various entity encoding formats
§Examples
use redstr::html_entity_encode;
let result = html_entity_encode("<script>");
// Example: "<script>" (varies each run)
// XSS payload with entity encoding
let xss = html_entity_encode("<img src=x onerror=alert(1)>");
// Bypasses filters looking for literal "<" and ">"
// Special character encoding
let special = html_entity_encode("A&B<C>D");
// Example: "A&B<C>D"