| Crates.io | hescape |
| lib.rs | hescape |
| version | 0.1.0 |
| created_at | 2026-01-17 08:14:35.483088+00 |
| updated_at | 2026-01-17 08:14:35.483088+00 |
| description | A fast and lightweight HTML escape/unescape library for Rust. |
| homepage | https://github.com/devashishdxt/hescape |
| repository | https://github.com/devashishdxt/hescape |
| max_upload_size | |
| id | 2050131 |
| size | 148,197 |
A fast and lightweight HTML escape/unescape library for Rust.
This crate provides functions to escape and unescape HTML special characters, which is essential for preventing XSS (Cross-Site Scripting) attacks and correctly rendering user-provided content in HTML documents.
The escape function converts the following characters to their HTML entity equivalents:
| Character | Entity |
|---|---|
& |
& |
< |
< |
> |
> |
" |
" |
' |
' |
use hescape::escape;
let input = "<script>alert(\"xss\")</script>";
let escaped = escape(input);
assert_eq!(escaped, "<script>alert("xss")</script>");
The unescape function converts HTML entities back to their original characters.
It supports:
&, <, >, ", ', and many more.', <, etc.', <, etc.use hescape::unescape;
let input = "<div>Hello & welcome!</div>";
let unescaped = unescape(input);
assert_eq!(unescaped, "<div>Hello & welcome!</div>");
For performance-sensitive applications, you can use escape_to and unescape_to to write directly to any
type implementing core::fmt::Write:
use hescape::escape_to;
let mut buffer = String::new();
escape_to(&mut buffer, "Hello <world>").unwrap();
assert_eq!(buffer, "Hello <world>");
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.