Skip to content

Commit

Permalink
fix: do not panic when fetching invalid file url on Windows (denoland…
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
dsherret authored Dec 6, 2024
1 parent 796749c commit 9fe52b1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ base64.workspace = true
bytes.workspace = true
data-url.workspace = true
deno_core.workspace = true
deno_path_util.workspace = true
deno_permissions.workspace = true
deno_tls.workspace = true
dyn-clone = "1"
Expand Down
6 changes: 5 additions & 1 deletion ext/fetch/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ use deno_core::OpState;
use deno_core::RcRef;
use deno_core::Resource;
use deno_core::ResourceId;
use deno_path_util::url_from_file_path;
use deno_path_util::PathToUrlError;
use deno_permissions::PermissionCheckError;
use deno_tls::rustls::RootCertStore;
use deno_tls::Proxy;
Expand Down Expand Up @@ -172,6 +174,8 @@ pub enum FetchError {
NetworkError,
#[error("Fetching files only supports the GET method: received {0}")]
FsNotGet(Method),
#[error(transparent)]
PathToUrl(#[from] PathToUrlError),
#[error("Invalid URL {0}")]
InvalidUrl(Url),
#[error(transparent)]
Expand Down Expand Up @@ -436,7 +440,7 @@ where
let permissions = state.borrow_mut::<FP>();
let path = permissions.check_read(&path, "fetch()")?;
let url = match path {
Cow::Owned(path) => Url::from_file_path(path).unwrap(),
Cow::Owned(path) => url_from_file_path(&path)?,
Cow::Borrowed(_) => url,
};

Expand Down
1 change: 1 addition & 0 deletions runtime/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ fn get_fetch_error(error: &FetchError) -> &'static str {
FetchError::Permission(e) => get_permission_check_error_class(e),
FetchError::NetworkError => "TypeError",
FetchError::FsNotGet(_) => "TypeError",
FetchError::PathToUrl(_) => "TypeError",
FetchError::InvalidUrl(_) => "TypeError",
FetchError::InvalidHeaderName(_) => "TypeError",
FetchError::InvalidHeaderValue(_) => "TypeError",
Expand Down

0 comments on commit 9fe52b1

Please sign in to comment.