Skip to main content

sanitize_message

Function sanitize_message 

Source
pub fn sanitize_message(msg: &str) -> String
Expand description

Sanitize a message by removing dangerous escape sequences and control characters.

  1. Removes ANSI escape sequences
  2. Removes OSC sequences (terminal commands)
  3. Removes CSI sequences
  4. Removes control characters except \n, \t, \r
  5. Removes invisible characters (see is_invisible) and normalises carriage returns (\r\n → \n, a lone \r dropped) — before any content check runs, so the text scanned is the text delivered
  6. Truncates to MAX_MESSAGE_LENGTH with UTF-8 safety