mirror of
https://github.com/denoland/deno.git
synced 2024-12-18 05:14:21 -05:00
fix: do not panic when fetching invalid file url on Windows (#27259)
I tried adding a test, but it's not possible due to a debug assertion in the url crate (https://github.com/servo/rust-url/issues/505) Closes https://github.com/denoland/deno/issues/27258
This commit is contained in:
parent
796749c807
commit
9fe52b1e8d
4 changed files with 8 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1623,6 +1623,7 @@ dependencies = [
|
|||
"bytes",
|
||||
"data-url",
|
||||
"deno_core",
|
||||
"deno_path_util",
|
||||
"deno_permissions",
|
||||
"deno_tls",
|
||||
"dyn-clone",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
@ -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)]
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue