1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix(vendor): properly handle bare specifiers that start with http (#16885)

This commit is contained in:
David Sherret 2022-12-01 11:01:19 -05:00 committed by GitHub
parent 0a82f3c0e9
commit fafb3eebaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View file

@ -1064,6 +1064,41 @@ mod test {
);
}
#[tokio::test]
async fn existing_import_map_http_key() {
let mut builder = VendorTestBuilder::with_default_setup();
let mut original_import_map = builder.new_import_map("/import_map.json");
original_import_map
.imports_mut()
.append(
"http/".to_string(),
"https://deno.land/std/http/".to_string(),
)
.unwrap();
let output = builder
.with_loader(|loader| {
loader.add("/mod.ts", "import 'http/mod.ts';");
loader.add("https://deno.land/std/http/mod.ts", "console.log(5);");
})
.set_original_import_map(original_import_map.clone())
.build()
.await
.unwrap();
assert_eq!(
output.import_map,
Some(json!({
"imports": {
"http/mod.ts": "./deno.land/std/http/mod.ts",
"https://deno.land/": "./deno.land/",
}
}))
);
assert_eq!(
output.files,
to_file_vec(&[("/vendor/deno.land/std/http/mod.ts", "console.log(5);")]),
);
}
#[tokio::test]
async fn vendor_file_fails_loading_dynamic_import() {
let mut builder = VendorTestBuilder::with_default_setup();

View file

@ -69,7 +69,8 @@ pub fn is_remote_specifier(specifier: &ModuleSpecifier) -> bool {
}
pub fn is_remote_specifier_text(text: &str) -> bool {
text.trim_start().to_lowercase().starts_with("http")
let text = text.trim_start().to_lowercase();
text.starts_with("http:") || text.starts_with("https:")
}
pub fn sanitize_filepath(text: &str) -> String {