diff --git a/src/api.rs b/src/api.rs index 9971c24..2de873c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -82,7 +82,7 @@ pub fn get_api_handler(collection: Arc) -> Mount { } fn path_from_request(request: &Request) -> Result { - let path_string = request.url.path().join("\\"); + let path_string = request.url.path().join(&::std::path::MAIN_SEPARATOR.to_string()); let decoded_path = percent_decode(path_string.as_bytes()).decode_utf8()?; Ok(PathBuf::from(decoded_path.deref())) } diff --git a/src/config.rs b/src/config.rs index 0f2dc5e..ca57650 100644 --- a/src/config.rs +++ b/src/config.rs @@ -196,7 +196,7 @@ fn clean_path_string(path_string: &str) -> path::PathBuf { 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) + path::Path::new(&path_string).iter().collect() } #[test] @@ -213,10 +213,14 @@ fn test_clean_path_string() { assert_eq!(correct_path, clean_path_string(r#"C:/some/path"#)); assert_eq!(correct_path, clean_path_string(r#"C:\some\path"#)); assert_eq!(correct_path, clean_path_string(r#"C:\some\path\"#)); + assert_eq!(correct_path, clean_path_string(r#"C:\some\path\\\\"#)); + assert_eq!(correct_path, clean_path_string(r#"C:\some/path//"#)); } else { assert_eq!(correct_path, clean_path_string(r#"/usr/some/path"#)); assert_eq!(correct_path, clean_path_string(r#"/usr\some\path"#)); assert_eq!(correct_path, clean_path_string(r#"/usr\some\path\"#)); + assert_eq!(correct_path, clean_path_string(r#"/usr\some\path\\\\"#)); + assert_eq!(correct_path, clean_path_string(r#"/usr\some/path//"#)); } } diff --git a/src/utils.rs b/src/utils.rs index f8846d0..4367f78 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -7,7 +7,8 @@ use errors::*; pub fn get_config_root() -> Result { if let Ok(mut root) = data_root(AppDataType::SharedConfig) { root.push("Polaris"); - fs::create_dir_all(&root)?; + fs::create_dir_all(&root) + .chain_err(|| format!("opening shared config: {}", root.display()))?; return Ok(root); } bail!("Could not retrieve config directory root"); @@ -16,7 +17,8 @@ pub fn get_config_root() -> Result { pub fn get_cache_root() -> Result { if let Ok(mut root) = data_root(AppDataType::SharedData) { root.push("Polaris"); - fs::create_dir_all(&root)?; + fs::create_dir_all(&root) + .chain_err(|| format!("opening shared data: {}", root.display()))?; return Ok(root); } bail!("Could not retrieve cache directory root");