Function rustful::file::check_path
[−]
[src]
pub fn check_path<P: ?Sized + AsRef<Path>>(path: &P) -> Result<(), Component>
Check if a path tries to escape its parent directory.
Forbidden path components:
- Root directory
- Prefixes (e.g.
C:
on Windows) - Parent directory
Allowed path components:
- "Normal" components (e.g.
res/scripts
) - Current directory
The first forbidden component is returned if the path is invalid.
use std::path::Component; use rustful::file::check_path; let bad_path = ".."; assert_eq!(check_path(bad_path), Err(Component::ParentDir));