Skip to content

Commit

Permalink
fix: handle file: specifiers with hosts (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Sep 27, 2024
1 parent f695a4c commit fca7258
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ fn url_to_file_path_inner(url: &Url) -> Result<PathBuf, ()> {
#[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
fn url_to_file_path_real(url: &Url) -> Result<PathBuf, ()> {
if cfg!(windows) {
if url.host().is_some() {
return Err(());
}

match url.to_file_path() {
Ok(path) => Ok(path),
Err(()) => {
Expand Down Expand Up @@ -329,10 +333,19 @@ mod tests {
"/dir/test test/test.txt",
);

assert_no_panic_specifier_to_file_path("file:/");
assert_no_panic_specifier_to_file_path("file://");
assert_no_panic_specifier_to_file_path("file://asdf/");
assert_no_panic_specifier_to_file_path("file://asdf/66666/a.ts");

fn run_success_test(specifier: &str, expected_path: &str) {
let result = url_to_file_path(&Url::parse(specifier).unwrap()).unwrap();
assert_eq!(result, PathBuf::from(expected_path));
}

fn assert_no_panic_specifier_to_file_path(specifier: &str) {
let _result = url_to_file_path(&Url::parse(specifier).unwrap());
}
}

#[test]
Expand Down

0 comments on commit fca7258

Please sign in to comment.