Skip to main content

sanitize_applescript_payload

Function sanitize_applescript_payload 

Source
pub fn sanitize_applescript_payload(s: &str, max: usize) -> String
Expand description

Sanitize a string for safe inclusion inside an AppleScript "..." literal.

Steps applied in order (order is important):

  1. Replace all ASCII control characters (< 0x20) and Unicode control chars with space (tab \t is also replaced — single-line banners only)
  2. Replace newlines \n and carriage returns \r with a single space
  3. Truncate to max chars, appending when cut
  4. Strip \ and "AppleScript does not support backslash escaping inside strings, so these characters must be removed to prevent injection

§Examples

let s = sanitize_applescript_payload("Hello\nWorld\"", 200);
assert_eq!(s, "Hello World");