pub fn sanitize_string(input: &str) -> Result<String>Expand description
Sanitize string by removing control characters
Removes all control characters except whitespace (space, tab, newline).
This provides defense-in-depth even when used after validate_input.
§Security Considerations
- Removes null bytes
- Removes other control characters that could interfere with terminal output
- Preserves legitimate whitespace
§Errors
Returns error if null byte is detected (fail-fast for security)
§Examples
use backup_suite::core::validation::sanitize_string;
// Normal text passes through
assert_eq!(sanitize_string("Hello World").unwrap(), "Hello World");
// Null bytes are rejected
assert!(sanitize_string("test\0malicious").is_err());
// Control characters are removed
assert_eq!(sanitize_string("test\x01\x02data").unwrap(), "testdata");