diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/Cargo.toml | 1 | ||||
-rw-r--r-- | runtime/fs_util.rs | 4 | ||||
-rw-r--r-- | runtime/ops/os/mod.rs | 2 | ||||
-rw-r--r-- | runtime/ops/process.rs | 2 | ||||
-rw-r--r-- | runtime/permissions.rs | 2 | ||||
-rw-r--r-- | runtime/permissions/Cargo.toml | 1 | ||||
-rw-r--r-- | runtime/permissions/lib.rs | 85 |
7 files changed, 9 insertions, 88 deletions
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index ea2978c49..d999513d2 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -88,6 +88,7 @@ deno_kv.workspace = true deno_napi.workspace = true deno_net.workspace = true deno_node.workspace = true +deno_path_util.workspace = true deno_permissions.workspace = true deno_terminal.workspace = true deno_tls.workspace = true diff --git a/runtime/fs_util.rs b/runtime/fs_util.rs index 15ebafdf6..a858e9770 100644 --- a/runtime/fs_util.rs +++ b/runtime/fs_util.rs @@ -2,12 +2,10 @@ use deno_core::anyhow::Context; use deno_core::error::AnyError; +use deno_path_util::normalize_path; use std::path::Path; use std::path::PathBuf; -pub use deno_core::normalize_path; -pub use deno_permissions::specifier_to_file_path; - #[inline] pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> { if path.is_absolute() { diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 544031dd7..bd9260e97 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -4,11 +4,11 @@ use super::utils::into_string; use crate::worker::ExitCode; use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::normalize_path; use deno_core::op2; use deno_core::v8; use deno_core::OpState; use deno_node::NODE_ENV_VAR_ALLOWLIST; +use deno_path_util::normalize_path; use deno_permissions::PermissionsContainer; use serde::Serialize; use std::collections::HashMap; diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index 530dcf49b..f6555e932 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -689,7 +689,7 @@ fn resolve_cmd(cmd: &str, env: &RunEnv) -> Result<PathBuf, AnyError> { } fn resolve_path(path: &str, cwd: &Path) -> PathBuf { - deno_core::normalize_path(cwd.join(path)) + deno_path_util::normalize_path(cwd.join(path)) } fn check_run_permission( diff --git a/runtime/permissions.rs b/runtime/permissions.rs index 9b2737b4f..533319c4e 100644 --- a/runtime/permissions.rs +++ b/runtime/permissions.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; use deno_core::anyhow::bail; use deno_core::anyhow::Context; use deno_core::error::AnyError; -use deno_core::normalize_path; +use deno_path_util::normalize_path; use deno_permissions::AllowRunDescriptor; use deno_permissions::AllowRunDescriptorParseResult; use deno_permissions::DenyRunDescriptor; diff --git a/runtime/permissions/Cargo.toml b/runtime/permissions/Cargo.toml index 9821b6148..37500d3eb 100644 --- a/runtime/permissions/Cargo.toml +++ b/runtime/permissions/Cargo.toml @@ -15,6 +15,7 @@ path = "lib.rs" [dependencies] deno_core.workspace = true +deno_path_util.workspace = true deno_terminal.workspace = true fqdn = "0.3.4" libc.workspace = true diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs index 5d8e76125..e919b81b6 100644 --- a/runtime/permissions/lib.rs +++ b/runtime/permissions/lib.rs @@ -6,7 +6,6 @@ use deno_core::error::custom_error; use deno_core::error::type_error; use deno_core::error::uri_error; use deno_core::error::AnyError; -use deno_core::normalize_path; use deno_core::parking_lot::Mutex; use deno_core::serde::de; use deno_core::serde::Deserialize; @@ -16,6 +15,8 @@ use deno_core::serde_json; use deno_core::unsync::sync::AtomicFlag; use deno_core::url::Url; use deno_core::ModuleSpecifier; +use deno_path_util::normalize_path; +use deno_path_util::url_to_file_path; use deno_terminal::colors; use fqdn::FQDN; use once_cell::sync::Lazy; @@ -2032,52 +2033,6 @@ impl Permissions { } } -/// Attempts to convert a specifier to a file path. By default, uses the Url -/// crate's `to_file_path()` method, but falls back to try and resolve unix-style -/// paths on Windows. -pub fn specifier_to_file_path( - specifier: &ModuleSpecifier, -) -> Result<PathBuf, AnyError> { - let result = if specifier.scheme() != "file" { - Err(()) - } else if cfg!(windows) { - if specifier.host().is_some() { - Err(()) - } else { - match specifier.to_file_path() { - Ok(path) => Ok(path), - Err(()) => { - // This might be a unix-style path which is used in the tests even on Windows. - // Attempt to see if we can convert it to a `PathBuf`. This code should be removed - // once/if https://github.com/servo/rust-url/issues/730 is implemented. - if specifier.scheme() == "file" - && specifier.port().is_none() - && specifier.path_segments().is_some() - { - let path_str = specifier.path(); - match String::from_utf8( - percent_encoding::percent_decode(path_str.as_bytes()).collect(), - ) { - Ok(path_str) => Ok(PathBuf::from(path_str)), - Err(_) => Err(()), - } - } else { - Err(()) - } - } - } - } - } else { - specifier.to_file_path() - }; - match result { - Ok(path) => Ok(path), - Err(()) => Err(uri_error(format!( - "Invalid file path.\n Specifier: {specifier}" - ))), - } -} - #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub enum CheckSpecifierKind { Static, @@ -2130,7 +2085,7 @@ impl PermissionsContainer { return Ok(()); } - match specifier_to_file_path(specifier) { + match url_to_file_path(specifier) { Ok(path) => inner.read.check( &PathQueryDescriptor { requested: path.to_string_lossy().into_owned(), @@ -4453,38 +4408,4 @@ mod tests { ); } } - - #[test] - fn test_specifier_to_file_path() { - run_success_test("file:///", "/"); - run_success_test("file:///test", "/test"); - run_success_test("file:///dir/test/test.txt", "/dir/test/test.txt"); - run_success_test( - "file:///dir/test%20test/test.txt", - "/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 = - specifier_to_file_path(&ModuleSpecifier::parse(specifier).unwrap()) - .unwrap(); - assert_eq!(result, PathBuf::from(expected_path)); - } - fn assert_no_panic_specifier_to_file_path(specifier: &str) { - let result = - specifier_to_file_path(&ModuleSpecifier::parse(specifier).unwrap()); - match result { - Ok(_) => (), - Err(err) => assert_eq!( - err.to_string(), - format!("Invalid file path.\n Specifier: {specifier}") - ), - } - } - } } |