strict-path 0.2.0

Secure path handling for untrusted input. Prevents directory traversal, symlink escapes, and 19+ real-world CVE attack patterns.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::PathBoundary;

#[test]
fn virtualpath_display_is_rooted_and_forward_slashed() {
    let temp = tempfile::tempdir().unwrap();
    let restriction = PathBoundary::<()>::try_new(temp.path()).unwrap();

    // Non-root path
    let jp = restriction.strict_join("foo/bar.txt").unwrap();
    let vp = jp.virtualize();
    assert_eq!(vp.virtualpath_display().to_string(), "/foo/bar.txt");
    assert_eq!(vp.virtualpath_display().to_string(), "/foo/bar.txt");

    // Root path
    let root_vp: crate::path::virtual_path::VirtualPath<()> =
        crate::path::virtual_path::VirtualPath::with_root(restriction.interop_path()).unwrap();
    assert_eq!(root_vp.virtualpath_display().to_string(), "/");
}