From cf0b3588a312d9c25ea49e82d40675ea94fcbfdd Mon Sep 17 00:00:00 2001 From: WofWca Date: Wed, 2 Apr 2025 21:02:48 +0400 Subject: [PATCH] docs: add `SafePathBuf` examples (#13122) --- crates/tauri/src/path/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/tauri/src/path/mod.rs b/crates/tauri/src/path/mod.rs index f9f79bed3..b6d2c6ea4 100644 --- a/crates/tauri/src/path/mod.rs +++ b/crates/tauri/src/path/mod.rs @@ -27,6 +27,17 @@ pub use android::PathResolver; pub use desktop::PathResolver; /// A wrapper for [`PathBuf`] that prevents path traversal. +/// +/// # Examples +/// +/// ``` +/// # use tauri::path::SafePathBuf; +/// 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()); +/// ``` #[derive(Clone, Debug, Serialize)] pub struct SafePathBuf(PathBuf);