Skip to content

Commit 9fe52b1

Browse files
authored
fix: do not panic when fetching invalid file url on Windows (denoland#27259)
I tried adding a test, but it's not possible due to a debug assertion in the url crate (servo/rust-url#505) Closes denoland#27258
1 parent 796749c commit 9fe52b1

4 files changed

Lines changed: 8 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/fetch/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ base64.workspace = true
1818
bytes.workspace = true
1919
data-url.workspace = true
2020
deno_core.workspace = true
21+
deno_path_util.workspace = true
2122
deno_permissions.workspace = true
2223
deno_tls.workspace = true
2324
dyn-clone = "1"

ext/fetch/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ use deno_core::OpState;
4141
use deno_core::RcRef;
4242
use deno_core::Resource;
4343
use deno_core::ResourceId;
44+
use deno_path_util::url_from_file_path;
45+
use deno_path_util::PathToUrlError;
4446
use deno_permissions::PermissionCheckError;
4547
use deno_tls::rustls::RootCertStore;
4648
use deno_tls::Proxy;
@@ -172,6 +174,8 @@ pub enum FetchError {
172174
NetworkError,
173175
#[error("Fetching files only supports the GET method: received {0}")]
174176
FsNotGet(Method),
177+
#[error(transparent)]
178+
PathToUrl(#[from] PathToUrlError),
175179
#[error("Invalid URL {0}")]
176180
InvalidUrl(Url),
177181
#[error(transparent)]
@@ -436,7 +440,7 @@ where
436440
let permissions = state.borrow_mut::<FP>();
437441
let path = permissions.check_read(&path, "fetch()")?;
438442
let url = match path {
439-
Cow::Owned(path) => Url::from_file_path(path).unwrap(),
443+
Cow::Owned(path) => url_from_file_path(&path)?,
440444
Cow::Borrowed(_) => url,
441445
};
442446

runtime/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ fn get_fetch_error(error: &FetchError) -> &'static str {
696696
FetchError::Permission(e) => get_permission_check_error_class(e),
697697
FetchError::NetworkError => "TypeError",
698698
FetchError::FsNotGet(_) => "TypeError",
699+
FetchError::PathToUrl(_) => "TypeError",
699700
FetchError::InvalidUrl(_) => "TypeError",
700701
FetchError::InvalidHeaderName(_) => "TypeError",
701702
FetchError::InvalidHeaderValue(_) => "TypeError",

0 commit comments

Comments
 (0)