pub fn sanitize_path(path: &str) -> String
Expand description
Sanitize a file path for safe usage
This function removes potentially dangerous path components like “..” and normalizes path separators to prevent directory traversal attacks and other security issues.
§Arguments
path
- The file path to sanitize
§Returns
A sanitized version of the input path.
§Examples
use tree_parser::sanitize_path;
assert_eq!(sanitize_path("../../../etc/passwd"), "etc/passwd");
assert_eq!(sanitize_path("src//main.rs"), "src/main.rs");
assert_eq!(sanitize_path("/absolute/path"), "absolute/path");