mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
docs: add SafePathBuf examples (#13122)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user