pub fn sanitize_applescript_payload(s: &str, max: usize) -> StringExpand description
Sanitize a string for safe inclusion inside an AppleScript "..." literal.
Steps applied in order (order is important):
- Replace all ASCII control characters (< 0x20) and Unicode control chars with space
(tab
\tis also replaced — single-line banners only) - Replace newlines
\nand carriage returns\rwith a single space - Truncate to
maxchars, appending…when cut - Strip
\and"—AppleScriptdoes 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");