pub fn url_encode(input: &str) -> StringExpand description
Encodes text with URL/percent encoding (RFC 3986).
Converts characters to percent-encoded format (%XX) where unreserved
characters (A-Z, a-z, 0-9, -, _, ., ~) remain unchanged. Properly
handles multi-byte UTF-8 characters by encoding each byte separately.
§Use Cases
- URL Construction: Safely encode query parameters and path segments
- Red Team: Bypass input filters with encoded payloads
- API Testing: Encode special characters in HTTP requests
- Blue Team: Test URL parser and decoder implementations
§Examples
use redstr::url_encode;
assert_eq!(url_encode("hello world"), "hello%20world");
assert_eq!(url_encode("user@example.com"), "user%40example.com");
// XSS payload encoding
let xss = url_encode("<script>alert(1)</script>");
// Output: "%3Cscript%3Ealert%281%29%3C%2Fscript%3E"
// SQL injection encoding
let sql = url_encode("' OR '1'='1");
// Output: "%27%20OR%20%271%27%3D%271"