relative-path icon indicating copy to clipboard operation
relative-path copied to clipboard

serde::Deserialize trait on RelativePathBuf permits absolute paths

Open jwodder opened this issue 3 years ago • 0 comments

Despite the fact that RelativePathBuf is supposed to reject any absolute paths, the following program:

use relative_path::RelativePathBuf;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Foo {
    path: RelativePathBuf
}

fn main() {
    let p = serde_json::from_str::<Foo>(r#"{"path": "/foo.txt"}"#);
    match p {
        Err(_) => println!("Task failed successfully"),
        Ok(v) => println!("Expected error, got {v:?}"),
    }
}

outputs:

Expected error, got Foo { path: "/foo.txt" }

jwodder avatar Oct 18 '22 14:10 jwodder