mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(imports): fix panic on unsupported scheme (#5131)
This commit is contained in:
parent
dabe88f854
commit
0ba90c8c11
4 changed files with 18 additions and 1 deletions
|
@ -93,7 +93,7 @@ impl SourceFileFetcher {
|
|||
Ok(file_fetcher)
|
||||
}
|
||||
|
||||
fn check_if_supported_scheme(url: &Url) -> Result<(), ErrBox> {
|
||||
pub fn check_if_supported_scheme(url: &Url) -> Result<(), ErrBox> {
|
||||
if !SUPPORTED_URL_SCHEMES.contains(&url.scheme()) {
|
||||
return Err(
|
||||
OpError::other(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
use crate::compilers::TargetLib;
|
||||
use crate::file_fetcher::SourceFileFetcher;
|
||||
use crate::global_state::GlobalState;
|
||||
use crate::global_timer::GlobalTimer;
|
||||
use crate::import_map::ImportMap;
|
||||
|
@ -474,6 +475,10 @@ impl State {
|
|||
module_specifier: &ModuleSpecifier,
|
||||
) -> Result<(), OpError> {
|
||||
let u = module_specifier.as_url();
|
||||
// TODO(bartlomieju): temporary fix to prevent hitting `unreachable`
|
||||
// statement that is actually reachable...
|
||||
SourceFileFetcher::check_if_supported_scheme(u)?;
|
||||
|
||||
match u.scheme() {
|
||||
"http" | "https" => {
|
||||
self.check_net_url(u)?;
|
||||
|
|
|
@ -1583,6 +1583,13 @@ itest!(run_v8_help {
|
|||
output: "v8_help.out",
|
||||
});
|
||||
|
||||
itest!(unsupported_dynamic_import_scheme {
|
||||
args: "eval import('xxx:')",
|
||||
output: "unsupported_dynamic_import_scheme.out",
|
||||
check_stderr: true,
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(wasm {
|
||||
args: "run wasm.ts",
|
||||
output: "wasm.ts.out",
|
||||
|
|
5
cli/tests/unsupported_dynamic_import_scheme.out
Normal file
5
cli/tests/unsupported_dynamic_import_scheme.out
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: Uncaught TypeError: Unsupported scheme "xxx" for module "xxx:". Supported schemes: [
|
||||
"http",
|
||||
"https",
|
||||
"file",
|
||||
]
|
Loading…
Reference in a new issue