Skip to content

Commit cf0b358

Browse files
authored
docs: add SafePathBuf examples (#13122)
1 parent b8c0d7e commit cf0b358

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/tauri/src/path/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ pub use android::PathResolver;
2727
pub use desktop::PathResolver;
2828

2929
/// A wrapper for [`PathBuf`] that prevents path traversal.
30+
///
31+
/// # Examples
32+
///
33+
/// ```
34+
/// # use tauri::path::SafePathBuf;
35+
/// assert!(SafePathBuf::new("../secret.txt".into()).is_err());
36+
/// assert!(SafePathBuf::new("/home/user/stuff/../secret.txt".into()).is_err());
37+
///
38+
/// assert!(SafePathBuf::new("./file.txt".into()).is_ok());
39+
/// assert!(SafePathBuf::new("/home/user/secret.txt".into()).is_ok());
40+
/// ```
3041
#[derive(Clone, Debug, Serialize)]
3142
pub struct SafePathBuf(PathBuf);
3243

0 commit comments

Comments
 (0)