diff --git a/src/config.rs b/src/config.rs index 33d7744..8a809b6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -192,19 +192,17 @@ impl Config { } fn clean_path_string(path_string: &str) -> path::PathBuf { - let separator = regex::Regex::new(r"\\|/").unwrap(); - let components = separator.split(path_string).collect::>(); - let mut path = path::PathBuf::new(); - for component in components { - path.push(component); - } - path + let separator_regex = regex::Regex::new(r"\\|/").unwrap(); + let mut correct_separator = String::new(); + correct_separator.push(path::MAIN_SEPARATOR); + let path_string = separator_regex.replace_all(path_string, correct_separator.as_str()); + path::PathBuf::from(path_string) } #[test] fn test_clean_path_string() { let mut correct_path = path::PathBuf::new(); - correct_path.push("C:"); + correct_path.push("C:\\"); correct_path.push("some"); correct_path.push("path"); assert_eq!(correct_path, clean_path_string(r#"C:/some/path"#));