Fix handling of dot folders

This commit is contained in:
Mihai Galos committed 2022-03-02 22:19:30 +01:00
1 parent 654cbe9a7e
commit acf8adf2d8
2 files changed
+12 -2

No files matched your search

+1 -1
View File
@@ -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"
+11 -1
View File
@@ -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");
}
}