diff --git a/src/escape.rs b/src/escape.rs index ba0ba5a..334623d 100644 --- a/src/escape.rs +++ b/src/escape.rs @@ -2,7 +2,7 @@ /// Escape HTML special characters for safe embedding in HTML content. /// -/// Escapes: `&`, `<`, `>`, `"` +/// Escapes: `&`, `<`, `>`, `"`, `'` pub fn html_escape(s: &str) -> String { let mut result = String::with_capacity(s.len()); html_escape_into(&mut result, s); @@ -19,6 +19,7 @@ pub fn html_escape_into(out: &mut String, s: &str) { '<' => out.push_str("<"), '>' => out.push_str(">"), '"' => out.push_str("""), + '\'' => out.push_str("'"), _ => out.push(c), } } @@ -44,6 +45,7 @@ mod tests { assert_eq!(html_escape("Hello & World"), "Hello & World"); assert_eq!(html_escape(""), "<tag>"); assert_eq!(html_escape("\"quoted\""), ""quoted""); + assert_eq!(html_escape("it's"), "it's"); } #[test]