Skip to content

Commit 9ec823b

Browse files
authored
fix: normalize a path when converting to a url (#13)
1 parent 8fc1738 commit 9ec823b

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,23 @@ pub struct PathToUrlError(pub PathBuf);
201201

202202
#[allow(clippy::result_unit_err)]
203203
pub fn url_from_file_path(path: &Path) -> Result<Url, PathToUrlError> {
204+
let path = normalize_path(Cow::Borrowed(path));
204205
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
205-
return Url::from_file_path(path)
206+
return Url::from_file_path(&path)
206207
.map_err(|()| PathToUrlError(path.to_path_buf()));
207208
#[cfg(not(any(unix, windows, target_os = "redox", target_os = "wasi")))]
208-
url_from_file_path_wasm(path).map_err(|()| PathToUrlError(path.to_path_buf()))
209+
url_from_file_path_wasm(&path)
210+
.map_err(|()| PathToUrlError(path.to_path_buf()))
209211
}
210212

211213
#[allow(clippy::result_unit_err)]
212214
pub fn url_from_directory_path(path: &Path) -> Result<Url, PathToUrlError> {
215+
let path = normalize_path(Cow::Borrowed(path));
213216
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
214-
return Url::from_directory_path(path)
217+
return Url::from_directory_path(&path)
215218
.map_err(|()| PathToUrlError(path.to_path_buf()));
216219
#[cfg(not(any(unix, windows, target_os = "redox", target_os = "wasi")))]
217-
url_from_directory_path_wasm(path)
220+
url_from_directory_path_wasm(&path)
218221
.map_err(|()| PathToUrlError(path.to_path_buf()))
219222
}
220223

0 commit comments

Comments
 (0)