HTML-escape the five significant characters so no interpolated string can inject markup.
(s: &str)
| 725 | /// HTML-escape the five significant characters so no interpolated string can |
| 726 | /// inject markup. |
| 727 | fn html_escape(s: &str) -> String { |
| 728 | let mut out = String::with_capacity(s.len()); |
| 729 | for ch in s.chars() { |
| 730 | match ch { |
| 731 | '&' => out.push_str("&"), |
| 732 | '<' => out.push_str("<"), |
| 733 | '>' => out.push_str(">"), |
| 734 | '"' => out.push_str("""), |
| 735 | '\'' => out.push_str("'"), |
| 736 | _ => out.push(ch), |
| 737 | } |
| 738 | } |
| 739 | out |
| 740 | } |
| 741 | |
| 742 | /// Escape a JSON payload for safe embedding inside a `<script>` element: the |
| 743 | /// `<`, `>`, and `&` bytes are rewritten to their `\u00XX` JSON escapes so the |
no test coverage detected