Skip to main content

normalise_path

Function normalise_path 

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

A repository-relative path as the scope judges it: forward slashes, no ./, no trailing slash. Absolute paths and parent segments are refused.

use majordomus_cli::capability::builtin::normalise_path;
assert_eq!(normalise_path("./docs/CLI.md").unwrap(), "docs/CLI.md");
assert_eq!(normalise_path("docs\\CLI.md").unwrap(), "docs/CLI.md");
assert_eq!(normalise_path("docs/").unwrap(), "docs");
assert!(normalise_path("/etc/passwd").is_err());
assert!(normalise_path("../x").is_err());
assert!(normalise_path("").is_err());