Skip to content

Commit

Permalink
fix(imports): fix panic on unsupported scheme (denoland#5131)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored and SASUKE40 committed May 7, 2020
1 parent a0d8937 commit 1625ef9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cli/file_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions cli/state.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)?;
Expand Down
7 changes: 7 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/unsupported_dynamic_import_scheme.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Uncaught TypeError: Unsupported scheme "xxx" for module "xxx:". Supported schemes: [
"http",
"https",
"file",
]

0 comments on commit 1625ef9

Please sign in to comment.