diff options
author | Maayan Hanin <maayan.asa.hanin@gmail.com> | 2021-01-04 11:33:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 04:33:20 -0500 |
commit | 1a6969bebbaaf2615b73a8582ba95be70a64c582 (patch) | |
tree | c2c0205ad508c72ea4cfc80d3cdcc519691fb1df /cli/disk_cache.rs | |
parent | 1a2e7741c33490d2a91147966019853c6b1d6a48 (diff) |
fix: panic on invalid file:// module specifier (#8964)
Diffstat (limited to 'cli/disk_cache.rs')
-rw-r--r-- | cli/disk_cache.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/cli/disk_cache.rs b/cli/disk_cache.rs index 81b86c0ae..3cc3b16f3 100644 --- a/cli/disk_cache.rs +++ b/cli/disk_cache.rs @@ -69,7 +69,10 @@ impl DiskCache { } "http" | "https" => out = url_to_filename(url), "file" => { - let path = url.to_file_path().unwrap(); + let path = match url.to_file_path() { + Ok(path) => path, + Err(_) => return None, + }; let mut path_components = path.components(); if cfg!(target_os = "windows") { @@ -278,4 +281,28 @@ mod tests { ) } } + + #[test] + fn test_get_cache_filename_invalid_urls() { + let cache_location = if cfg!(target_os = "windows") { + PathBuf::from(r"C:\deno_dir\") + } else { + PathBuf::from("/deno_dir/") + }; + + let cache = DiskCache::new(&cache_location); + + let mut test_cases = vec!["unknown://localhost/test.ts"]; + + if cfg!(target_os = "windows") { + test_cases.push("file://"); + test_cases.push("file:///"); + } + + for test_case in &test_cases { + let cache_filename = + cache.get_cache_filename(&Url::parse(test_case).unwrap()); + assert_eq!(cache_filename, None); + } + } } |