mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(vendor): do not panic on relative specifier with scheme-like folder name (#14453)
This commit is contained in:
parent
2080ea6f52
commit
1a7e9fb924
2 changed files with 51 additions and 1 deletions
49
cli/tools/vendor/build.rs
vendored
49
cli/tools/vendor/build.rs
vendored
|
@ -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)> {
|
||||
items
|
||||
.iter()
|
||||
|
|
3
cli/tools/vendor/import_map.rs
vendored
3
cli/tools/vendor/import_map.rs
vendored
|
@ -226,7 +226,8 @@ fn handle_dep_specifier(
|
|||
let mut local_base_specifier = mappings.local_uri(base_specifier);
|
||||
local_base_specifier.set_query(unresolved_specifier.query());
|
||||
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(|_| {
|
||||
panic!(
|
||||
"Error joining {} to {}",
|
||||
|
|
Loading…
Reference in a new issue