validatePath(path: string | null | undefined): string| Name | Type | Description |
|---|---|---|
path* | string | null | undefined | Path to validate |
validatePath("foo/bar") // Returns: "/foo/bar/"
validatePath("/./foo//bar") // Returns: "/foo/bar/"
validatePath("../etc/passwd") // Throws: Path traversal not allowed
validatePath("C:\\Users\\file") // Throws: Windows absolute paths not supportedValidate and normalize a directory path.
Ensures paths are safe to use by preventing directory traversal attacks and enforcing consistent formatting. All paths are normalized to use forward slashes and start with a leading slash.
This function is designed for virtual filesystem paths and rejects Windows absolute paths (e.g., C:/..., F:/...) to maintain consistency and prevent path format ambiguity.