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

Function html_escape

atomic-cli/src/commands/triage/output.rs:727–740  ·  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

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

Callers 2

render_changeFunction · 0.70
render_walkthroughFunction · 0.70

Calls 2

lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected