Skip to main content

xml_escape

Function xml_escape 

Source
pub fn xml_escape(s: &str) -> String
Expand description

Escape XML special characters in a string.

Replaces &, <, >, ", and ' with their XML entity equivalents. Use this when embedding arbitrary text into XML attributes or text nodes to prevent tag injection.

ยงExamples

use zeph_common::text::xml_escape;

assert_eq!(xml_escape("a < b && b > c"), "a &lt; b &amp;&amp; b &gt; c");
assert_eq!(xml_escape(r#"say "hi""#), "say &quot;hi&quot;");
assert_eq!(xml_escape("it's"), "it&#39;s");