1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

fix(imports): fix panic on unsupported scheme (#5131)

This commit is contained in:
Bartek Iwańczuk 2020-05-07 15:57:10 +02:00 committed by GitHub
parent dabe88f854
commit 0ba90c8c11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 1 deletions

View file

@ -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(

View file

@ -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)?;

View file

@ -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",

View file

@ -0,0 +1,5 @@
error: Uncaught TypeError: Unsupported scheme "xxx" for module "xxx:". Supported schemes: [
"http",
"https",
"file",
]