Shell-escape a value for use inside a `ProxyCommand` string.
(value: &str)
| 763 | |
| 764 | /// Shell-escape a value for use inside a `ProxyCommand` string. |
| 765 | pub fn shell_escape(value: &str) -> String { |
| 766 | if value.is_empty() { |
| 767 | return "''".to_string(); |
| 768 | } |
| 769 | |
| 770 | let safe = value |
| 771 | .bytes() |
| 772 | .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'/' | b'-' | b'_')); |
| 773 | if safe { |
| 774 | return value.to_string(); |
| 775 | } |
| 776 | |
| 777 | let escaped = value.replace('\'', "'\"'\"'"); |
| 778 | format!("'{escaped}'") |
| 779 | } |
| 780 | |
| 781 | /// Build the SSH `ProxyCommand` string used to tunnel to a sandbox. |
| 782 | /// |
no test coverage detected