normalize_and_validate_path

Function normalize_and_validate_path 

Source
pub fn normalize_and_validate_path(
    path: &Path,
    cwd: &Path,
) -> Result<PathBuf, PathTraversalError>
Expand description

Normalize a path and validate it stays within the cwd.

This is a secure version of path normalization that:

  1. Converts relative paths to absolute paths
  2. Cleans the path (removes . and .. components)
  3. Validates the path doesn’t escape the cwd

§Arguments

  • path - The path to normalize (can be relative or absolute)
  • cwd - The current working directory

§Returns

The normalized absolute path, or an error if path traversal is detected