pub fn unescape_chars(input: &str, escape_braces: bool) -> StringExpand description
Unescapes HTML entities in a given input string.
This function is designed specifically to reverse the escaping performed by escape_chars.
It is not intended to be a general-purpose HTML decoder. It replaces the following HTML
entities with their corresponding characters:
&→&<→<>→>"→"'→'/→/
If escape_braces is true, it also replaces:
{→{}→}
If an unrecognized entity is encountered, it is left unchanged in the output.
§Arguments
input- The input string containing HTML entities to unescape.escape_braces- A boolean flag indicating whether to unescape curly braces ({and}).- If
true,{and}are unescaped to{and}. - If
false,{and}are left unchanged.
- If
§Examples
Basic usage:
let input = "<script>alert("Hello & 'World'");</script>";
let unescaped = unescape_chars(input, false);
assert_eq!(unescaped, r#"<script>alert("Hello & 'World'");</script>"#);Unescaping curly braces:
let input = "{example}";
let unescaped = unescape_chars(input, true);
assert_eq!(unescaped, "{example}");Unrecognized entities are preserved:
let input = "This is an &unknown; entity.";
let unescaped = unescape_chars(input, false);
assert_eq!(unescaped, "This is an &unknown; entity.");