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

fix(vendor): do not panic on relative specifier with scheme-like folder name (#14453)

This commit is contained in:
David Sherret 2022-05-02 09:07:41 -04:00 committed by cjihrig
parent 2080ea6f52
commit 1a7e9fb924
No known key found for this signature in database
GPG key ID: 7434390BDBE9B9C5
2 changed files with 51 additions and 1 deletions

View file

@ -619,6 +619,55 @@ mod test {
); );
} }
#[tokio::test]
async fn remote_relative_specifier_with_scheme_like_folder_name() {
let mut builder = VendorTestBuilder::with_default_setup();
let output = builder
.with_loader(|loader| {
loader
.add("/mod.ts", "import 'https://localhost/mod.ts';")
.add(
"https://localhost/mod.ts",
"import './npm:test@1.0.0/test/test!cjs';",
)
.add_with_headers(
"https://localhost/npm:test@1.0.0/test/test!cjs",
"console.log(5);",
&[("content-type", "application/javascript")],
);
})
.build()
.await
.unwrap();
assert_eq!(
output.import_map,
Some(json!({
"imports": {
"https://localhost/": "./localhost/"
},
"scopes": {
"./localhost/": {
"./localhost/npm:test@1.0.0/test/test!cjs": "./localhost/npm_test@1.0.0/test/test!cjs.js"
}
}
}))
);
assert_eq!(
output.files,
to_file_vec(&[
(
"/vendor/localhost/mod.ts",
"import './npm:test@1.0.0/test/test!cjs';"
),
(
"/vendor/localhost/npm_test@1.0.0/test/test!cjs.js",
"console.log(5);"
),
]),
);
}
fn to_file_vec(items: &[(&str, &str)]) -> Vec<(String, String)> { fn to_file_vec(items: &[(&str, &str)]) -> Vec<(String, String)> {
items items
.iter() .iter()

View file

@ -226,7 +226,8 @@ fn handle_dep_specifier(
let mut local_base_specifier = mappings.local_uri(base_specifier); let mut local_base_specifier = mappings.local_uri(base_specifier);
local_base_specifier.set_query(unresolved_specifier.query()); local_base_specifier.set_query(unresolved_specifier.query());
local_base_specifier = local_base_specifier local_base_specifier = local_base_specifier
.join(&unresolved_specifier.path()[1..]) // path includes "/" so make it relative
.join(&format!(".{}", unresolved_specifier.path()))
.unwrap_or_else(|_| { .unwrap_or_else(|_| {
panic!( panic!(
"Error joining {} to {}", "Error joining {} to {}",