1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

fix(cli): import maps handles data URLs (#9437)

Fixes #9420
This commit is contained in:
Kitson Kelly 2021-02-09 15:05:37 +11:00 committed by GitHub
parent 36e9e53b37
commit 97d5ef2950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 9 deletions

View file

@ -34,9 +34,9 @@ impl fmt::Display for ImportMapError {
impl Error for ImportMapError {}
// NOTE: here is difference between deno and reference implementation - deno currently
// can't resolve URL with other schemes (eg. data:, about:, blob:)
const SUPPORTED_FETCH_SCHEMES: [&str; 3] = ["http", "https", "file"];
// NOTE: here is difference between deno and reference implementation - Deno
// doesn't resolve URLs outside of the supported schemes.
const SUPPORTED_FETCH_SCHEMES: [&str; 4] = ["http", "https", "file", "data"];
type SpecifierMap = IndexMap<String, Vec<ModuleSpecifier>>;
type ScopesMap = IndexMap<String, SpecifierMap>;
@ -863,9 +863,9 @@ mod tests {
"http://good/": {},
"https://good/": {},
"file:///good": {},
"data:good": {},
"about:bad": {},
"blob:bad": {},
"data:bad": {},
"filesystem:bad": {},
"ftp://bad/": {},
"import:bad": {},
@ -880,7 +880,8 @@ mod tests {
assert!(import_map.scopes.contains_key("http://good/"));
assert!(import_map.scopes.contains_key("https://good/"));
assert!(import_map.scopes.contains_key("file:///good"));
assert_eq!(import_map.scopes.len(), 3);
assert!(import_map.scopes.contains_key("data:good"));
assert_eq!(import_map.scopes.len(), 4);
// Should parse absolute URL scope keys, ignoring unparseable ones..
let json_map = r#"{
@ -994,9 +995,9 @@ mod tests {
"http": "http://good/",
"https": "https://good/",
"file": "file:///good",
"data": "data:good",
"about": "about:bad",
"blob": "blob:bad",
"data": "data:bad",
"filesystem": "filesystem:bad",
"ftp": "ftp://good/",
"import": "import:bad",
@ -1021,10 +1022,13 @@ mod tests {
import_map.imports.get("https").unwrap(),
&vec!["https://good/".to_string()]
);
assert_eq!(
import_map.imports.get("data").unwrap(),
&vec!["data:good".to_string()]
);
assert!(import_map.imports.get("about").unwrap().is_empty());
assert!(import_map.imports.get("blob").unwrap().is_empty());
assert!(import_map.imports.get("data").unwrap().is_empty());
assert!(import_map.imports.get("filesystem").unwrap().is_empty());
assert!(import_map.imports.get("ftp").unwrap().is_empty());
assert!(import_map.imports.get("import").unwrap().is_empty());
@ -1041,9 +1045,9 @@ mod tests {
"http": ["http://good/"],
"https": ["https://good/"],
"file": ["file:///good"],
"data": ["data:good"],
"about": ["about:bad"],
"blob": ["blob:bad"],
"data": ["data:bad"],
"filesystem": ["filesystem:bad"],
"ftp": ["ftp://good/"],
"import": ["import:bad"],
@ -1068,10 +1072,13 @@ mod tests {
import_map.imports.get("https").unwrap(),
&vec!["https://good/".to_string()]
);
assert_eq!(
import_map.imports.get("data").unwrap(),
&vec!["data:good".to_string()]
);
assert!(import_map.imports.get("about").unwrap().is_empty());
assert!(import_map.imports.get("blob").unwrap().is_empty());
assert!(import_map.imports.get("data").unwrap().is_empty());
assert!(import_map.imports.get("filesystem").unwrap().is_empty());
assert!(import_map.imports.get("ftp").unwrap().is_empty());
assert!(import_map.imports.get("import").unwrap().is_empty());
@ -2069,4 +2076,15 @@ mod tests {
"https://example.com/app/none.mjs",
);
}
#[test]
fn resolve_data_urls() {
let base_url = "https://example.com/app/main.ts";
let json_map = r#"{}"#;
let import_map = ImportMap::from_json(base_url, json_map).unwrap();
assert_resolve(
import_map.resolve("data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=", base_url),
"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=",
);
}
}

View file

@ -3577,6 +3577,11 @@ console.log("finish");
exit_code: 1,
});
itest!(import_data_url_import_map {
args: "run --quiet --reload --unstable --import-map import_maps/import_map.json import_data_url.ts",
output: "import_data_url.ts.out",
});
itest!(import_data_url_imports {
args: "run --quiet --reload import_data_url_imports.ts",
output: "import_data_url_imports.ts.out",