Lexically clean a POSIX-style absolute path by resolving `.` and `..` components, collapsing repeated separators, and stripping any trailing slash. Returns `None` if the input is empty or relative — the caller is expected to reject those before reaching this helper. This is *lexical* only: it does not consult the filesystem and so cannot follow symlinks. That trade-off is intentional — the functi
(path: &str)
| 827 | /// SSH command. Symlink-based escapes inside the sandbox must be addressed |
| 828 | /// server-side. |
| 829 | fn lexical_clean_absolute_path(path: &str) -> Option<String> { |
| 830 | if !path.starts_with('/') { |
| 831 | return None; |
| 832 | } |
| 833 | let mut stack: Vec<&str> = Vec::new(); |
| 834 | for component in path.split('/') { |
| 835 | match component { |
| 836 | "" | "." => {} |
| 837 | ".." => { |
| 838 | stack.pop(); |
| 839 | } |
| 840 | other => stack.push(other), |
| 841 | } |
| 842 | } |
| 843 | if stack.is_empty() { |
| 844 | return Some("/".to_string()); |
| 845 | } |
| 846 | let mut out = String::with_capacity(path.len()); |
| 847 | for component in stack { |
| 848 | out.push('/'); |
| 849 | out.push_str(component); |
| 850 | } |
| 851 | Some(out) |
| 852 | } |
| 853 | |
| 854 | /// Validate that a sandbox-side source path passed to `sandbox download` |
| 855 | /// resolves under the sandbox writable root. |
no test coverage detected