Skip to main content

sanitized

Macro sanitized 

Source
macro_rules! sanitized {
    ($expr:expr) => { ... };
}
Expand description

Sanitize untrusted input for inclusion in error messages.

§Behavior

  • Truncates strings to MAX_SANITIZED_LEN characters, respecting UTF-8 boundaries.
  • Replaces control characters with ‘?’ to prevent log injection or formatting issues.
  • Handles non-string types by converting to string first.
  • For fully control-char inputs exceeding length, uses “[INVALID_INPUT]”.

§Allocation

  • Allocates a new String for the sanitized output.

§Example

let long = "A".repeat(300);
let san = sanitized!(long);
assert!(san.len() <= 256 + 13);
assert!(san.ends_with("[TRUNCATED]"));