MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / html_escape

Function html_escape

atomic-cli/src/commands/triage/output.rs:735–748  ·  view source on GitHub ↗

HTML-escape the five significant characters so no interpolated string can inject markup.

(s: &str)

Source from the content-addressed store, hash-verified

733/// HTML-escape the five significant characters so no interpolated string can
734/// inject markup.
735fn 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("&lt;"),
741 '>' => out.push_str("&gt;"),
742 '"' => out.push_str("&quot;"),
743 '\'' => out.push_str("&#39;"),
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

Callers 2

render_changeFunction · 0.70
render_walkthroughFunction · 0.70

Calls 2

lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected