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

Function html_escape

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

493/// HTML-escape the five significant characters so no interpolated string can
494/// inject markup.
495fn html_escape(s: &str) -> String {
496 let mut out = String::with_capacity(s.len());
497 for ch in s.chars() {
498 match ch {
499 '&' => out.push_str("&"),
500 '<' => out.push_str("&lt;"),
501 '>' => out.push_str("&gt;"),
502 '"' => out.push_str("&quot;"),
503 '\'' => out.push_str("&#39;"),
504 _ => out.push(ch),
505 }
506 }
507 out
508}
509
510/// Escape a JSON payload for safe embedding inside a `<script>` element: the
511/// `<`, `>`, and `&` bytes are rewritten to their `\u00XX` JSON escapes so the

Callers 1

render_changeFunction · 0.70

Calls 2

lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected