pub fn validate_path_chars(path: &str) -> Result<()>Expand description
Validates that a path contains only characters valid for the current platform.
This function checks path strings for invalid characters and reserved names according to platform-specific filesystem rules. It helps prevent errors when creating files and directories.
§Arguments
path- The path string to validate
§Returns
Ok(())if the path is valid for the current platformErrif the path contains invalid characters or reserved names
§Examples
use agpm_cli::utils::platform::validate_path_chars;
// Valid paths
validate_path_chars("valid/path/file.txt")?;
validate_path_chars("another_valid_file.md")?;
// Invalid on Windows (but may be valid on Unix)
let result = validate_path_chars("invalid:file.txt");
assert!(result.is_err());§Platform-Specific Rules
§Windows
Invalid characters: < > : " | ? * and control characters (0x00-0x1F)
Reserved names: CON, PRN, AUX, NUL, COM1-COM9, LPT1-LPT9
(case-insensitive, applies to bare names without extensions)
§Unix-like Systems
- Only the null character (
\0) is invalid - No reserved names (though some names like
.and..have special meaning) - Case-sensitive validation
§Use Cases
- Validating user input for file names
- Checking paths before creation
- Preventing filesystem errors
- Cross-platform path compatibility
§Security
This validation helps prevent:
- Filesystem errors from invalid characters
- Accidental overwriting of system files (Windows reserved names)
- Path injection attacks using special characters
§Limitations
- Does not check path length limits
- Does not verify directory existence
- May not catch all filesystem-specific restrictions
§See Also
safe_joinwhich uses this function for validation- Platform filesystem documentation for complete rules