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