pub fn sanitize_command(
command: &str,
max_chars: Option<usize>,
) -> Result<String>Expand description
Sanitize a command before execution
This function:
- Validates that the command is not empty
- Trims whitespace
- Checks length against max_chars limit
§Arguments
command- The raw command stringmax_chars- Optional maximum character limit (None = unlimited)
§Returns
Ok(String)- The sanitized commandErr(SshMcpError::InvalidParams)- If command is empty or too long
§Examples
use ssh_mcp::ssh::sanitize::sanitize_command;
let cmd = sanitize_command(" ls -la ", Some(1000)).unwrap();
assert_eq!(cmd, "ls -la");
// Too long command
let result = sanitize_command("a".repeat(100).as_str(), Some(50));
assert!(result.is_err());