diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2021-02-17 13:47:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-17 13:47:18 -0500 |
commit | c7dabc99eed50fa20cdcafd7c0175ab615da3d50 (patch) | |
tree | ec2c611c627827bbdd61d3e27400ae1b9a50d459 /runtime/permissions.rs | |
parent | f6d6b24506410816833d802e1a8d9cd704f73289 (diff) |
Make ModuleSpecifier a type alias, not wrapper struct (#9531)
Diffstat (limited to 'runtime/permissions.rs')
-rw-r--r-- | runtime/permissions.rs | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/runtime/permissions.rs b/runtime/permissions.rs index b568c0a4f..e89a8747d 100644 --- a/runtime/permissions.rs +++ b/runtime/permissions.rs @@ -580,9 +580,8 @@ impl Permissions { &self, specifier: &ModuleSpecifier, ) -> Result<(), AnyError> { - let url = specifier.as_url(); - match url.scheme() { - "file" => match url.to_file_path() { + match specifier.scheme() { + "file" => match specifier.to_file_path() { Ok(path) => self.check_read(&path), Err(_) => Err(uri_error(format!( "Invalid file path.\n Specifier: {}", @@ -590,7 +589,7 @@ impl Permissions { ))), }, "data" => Ok(()), - _ => self.check_net_url(url), + _ => self.check_net_url(specifier), } } @@ -749,6 +748,7 @@ fn format_host<T: AsRef<str>>(host: &(T, Option<u16>)) -> String { #[cfg(test)] mod tests { use super::*; + use deno_core::resolve_url_or_path; // Creates vector of strings, Vec<String> macro_rules! svec { @@ -1000,42 +1000,27 @@ mod tests { let mut fixtures = vec![ ( - ModuleSpecifier::resolve_url_or_path("http://localhost:4545/mod.ts") - .unwrap(), + resolve_url_or_path("http://localhost:4545/mod.ts").unwrap(), true, ), ( - ModuleSpecifier::resolve_url_or_path("http://deno.land/x/mod.ts") - .unwrap(), + resolve_url_or_path("http://deno.land/x/mod.ts").unwrap(), false, ), ( - ModuleSpecifier::resolve_url_or_path( - "data:text/plain,Hello%2C%20Deno!", - ) - .unwrap(), + resolve_url_or_path("data:text/plain,Hello%2C%20Deno!").unwrap(), true, ), ]; if cfg!(target_os = "windows") { - fixtures.push(( - ModuleSpecifier::resolve_url_or_path("file:///C:/a/mod.ts").unwrap(), - true, - )); - fixtures.push(( - ModuleSpecifier::resolve_url_or_path("file:///C:/b/mod.ts").unwrap(), - false, - )); + fixtures + .push((resolve_url_or_path("file:///C:/a/mod.ts").unwrap(), true)); + fixtures + .push((resolve_url_or_path("file:///C:/b/mod.ts").unwrap(), false)); } else { - fixtures.push(( - ModuleSpecifier::resolve_url_or_path("file:///a/mod.ts").unwrap(), - true, - )); - fixtures.push(( - ModuleSpecifier::resolve_url_or_path("file:///b/mod.ts").unwrap(), - false, - )); + fixtures.push((resolve_url_or_path("file:///a/mod.ts").unwrap(), true)); + fixtures.push((resolve_url_or_path("file:///b/mod.ts").unwrap(), false)); } for (specifier, expected) in fixtures { @@ -1058,7 +1043,7 @@ mod tests { for url in test_cases { assert!(perms - .check_specifier(&ModuleSpecifier::resolve_url_or_path(url).unwrap()) + .check_specifier(&resolve_url_or_path(url).unwrap()) .is_err()); } } |