Skip to main content

encode_safe

Function encode_safe 

Source
pub fn encode_safe(input: &str) -> Cow<'_, str>
Expand description

Minimal HTML escaper for the 6 XSS-critical characters (& < > " ' /). Returns Cow::Borrowed when no escaping is needed (zero allocation on the happy path), Cow::Owned when any character had to be replaced.

Re-exported here so external callers of RenderOptions::with_head_inject / with_body_inject can pre-escape untrusted content with the same escaper the handler uses internally for SSR text content, without having to pull in a separate HTML-escape crate. Characters escaped and their replacements:

  • & → &amp;
  • < → &lt;
  • > → &gt;
  • " → &quot;
  • ' → &#x27;
  • / → &#x2F;

Returns Cow::Borrowed when the input contains no characters that need escaping (zero-allocation fast path).