Skip to main content

normalize_artifact_path

Function normalize_artifact_path 

Source
pub fn normalize_artifact_path(raw: &str) -> Result<String, PathError>
Expand description

Normalize a workspace-relative artifact path to its canonical form.

Resolves . and .. components, strips redundant separators, and converts backslashes to forward slashes. The result is a clean relative path suitable for use as a map key and file identity.

§Errors

Returns PathError if the path is empty, absolute, or escapes the workspace root (net .. depth goes below zero).

§Examples

use perspt_core::path::normalize_artifact_path;

assert_eq!(normalize_artifact_path("src/main.rs").unwrap(), "src/main.rs");
assert_eq!(normalize_artifact_path("./src/main.rs").unwrap(), "src/main.rs");
assert_eq!(normalize_artifact_path("src/../src/main.rs").unwrap(), "src/main.rs");
assert_eq!(normalize_artifact_path("src/./main.rs").unwrap(), "src/main.rs");
assert!(normalize_artifact_path("../escape.rs").is_err());
assert!(normalize_artifact_path("/absolute/path").is_err());