pub struct SafePathBuf(/* private fields */);Expand description
A wrapper for PathBuf that prevents path traversal.
§Examples
assert!(SafePathBuf::new("../secret.txt".into()).is_err());
assert!(SafePathBuf::new("/home/user/stuff/../secret.txt".into()).is_err());
assert!(SafePathBuf::new("./file.txt".into()).is_ok());
assert!(SafePathBuf::new("/home/user/secret.txt".into()).is_ok());Implementations§
Source§impl SafePathBuf
impl SafePathBuf
Sourcepub fn new(path: PathBuf) -> Result<Self, &'static str>
pub fn new(path: PathBuf) -> Result<Self, &'static str>
Validates the path for directory traversal vulnerabilities and returns a new SafePathBuf instance if it is safe.
Sourcepub fn display(&self) -> Display<'_>
pub fn display(&self) -> Display<'_>
Returns an object that implements std::fmt::Display for safely printing paths.
See PathBuf for more information.
Trait Implementations§
Source§impl AsRef<Path> for SafePathBuf
impl AsRef<Path> for SafePathBuf
Source§impl Clone for SafePathBuf
impl Clone for SafePathBuf
Source§fn clone(&self) -> SafePathBuf
fn clone(&self) -> SafePathBuf
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SafePathBuf
impl Debug for SafePathBuf
Source§impl<'de> Deserialize<'de> for SafePathBuf
impl<'de> Deserialize<'de> for SafePathBuf
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl FromStr for SafePathBuf
impl FromStr for SafePathBuf
Auto Trait Implementations§
impl Freeze for SafePathBuf
impl RefUnwindSafe for SafePathBuf
impl Send for SafePathBuf
impl Sync for SafePathBuf
impl Unpin for SafePathBuf
impl UnwindSafe for SafePathBuf
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more