[][src]Function crev_common::sanitize_url_for_fs

pub fn sanitize_url_for_fs(url: &str) -> PathBuf

Takes an url and converts it to something safe for use in paths etc.

Examples

// Hash on escaped chars to avoid collisions
assert_eq!(sanitize_url_for_fs("https://crates.io"), Path::new("crates_io-yTEHLALL07ZuqIYj8EHFkg"));

// Limit absurdly long names.  Combining a bunch of these can still run into filesystem limits however.
let a48   = std::iter::repeat("a").take(  48).collect::<String>();
let a2048 = std::iter::repeat("a").take(2048).collect::<String>();
let a2049 = std::iter::repeat("a").take(2049).collect::<String>();
assert_eq!(sanitize_url_for_fs(a2048.as_str()).to_str().unwrap(), format!("{}-4iupJgrBwxluPQ8DRmrnXg", a48));
assert_eq!(sanitize_url_for_fs(a2049.as_str()).to_str().unwrap(), format!("{}-VMRqy6kfWHPoPp1iKIGt1A", a48));