Fix handling of dot folders
This commit is contained in:
parent
654cbe9a7e
commit
acf8adf2d8
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "untildify"
|
||||
description = "Utility to replace ~ with user home directory."
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
|
||||
12
src/lib.rs
12
src/lib.rs
@ -23,7 +23,7 @@ pub fn untildify(input_path: &str) -> String {
|
||||
return match get_host_dir() {
|
||||
Some(path) => {
|
||||
let host_dir = path.to_str().unwrap();
|
||||
let re = Regex::new(r"^~([/\w]+)").unwrap();
|
||||
let re = Regex::new(r"^~([/\w.]+)").unwrap();
|
||||
match re.captures(input_path) {
|
||||
Some(captures) => {
|
||||
return format!("{}{}", host_dir, &captures[1]);
|
||||
@ -71,4 +71,14 @@ mod tests {
|
||||
assert_eq!(untildify("/"), "/");
|
||||
assert_eq!(untildify("~/Desktop/~/Code"), "/User/Untildify/Desktop/");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_dot_folders() {
|
||||
env::remove_var("HOME");
|
||||
|
||||
let home = Path::new("/User/Untildify");
|
||||
env::set_var("HOME", home.as_os_str());
|
||||
|
||||
assert_eq!(untildify("~/.ssh/id_rsa"), "/User/Untildify/.ssh/id_rsa");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user