summaryrefslogtreecommitdiff
path: root/cli/tools/installer.rs
diff options
context:
space:
mode:
authorYusuke Tanaka <yusuktan@maguro.dev>2022-10-12 11:32:52 +0900
committerGitHub <noreply@github.com>2022-10-12 11:32:52 +0900
commit2c96f64fa7ec7655200de4c6740ceade78a3fad7 (patch)
treef06758ca6f76b40a7915f9c19d4f2fbe3ad0ca43 /cli/tools/installer.rs
parent0cd05d737729b4cfab1d5e22077b3b9ad4ed5e30 (diff)
fix(cli): skip removing the latter part if `@` appears at the beginning (#16244)
This commit prevents panics that `deno compile` command ran into under certain conditions from occurring. Such conditions are as follows. - the target file name begins with `@`, OR - the stem part of the target file name is equal to one of ["main", "index", "mod", "index"] && the parent directory name starts with `@` Fixes #16243
Diffstat (limited to 'cli/tools/installer.rs')
-rw-r--r--cli/tools/installer.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index d1754562a..68810272e 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -135,7 +135,17 @@ pub fn infer_name_from_url(url: &Url) -> Option<String> {
stem = parent_name.to_string_lossy().to_string();
}
}
- let stem = stem.split_once('@').map_or(&*stem, |x| x.0).to_string();
+
+ // if atmark symbol appears in the index other than 0 (e.g. `foo@bar`) we use
+ // the former part as the inferred name because the latter part is most likely
+ // a version number.
+ match stem.find('@') {
+ Some(at_index) if at_index > 0 => {
+ stem = stem.split_at(at_index).0.to_string();
+ }
+ _ => {}
+ }
+
Some(stem)
}
@@ -479,6 +489,24 @@ mod tests {
),
Some("abc".to_string())
);
+ assert_eq!(
+ infer_name_from_url(&Url::parse("https://example.com/@abc.ts").unwrap()),
+ Some("@abc".to_string())
+ );
+ assert_eq!(
+ infer_name_from_url(
+ &Url::parse("https://example.com/@abc/mod.ts").unwrap()
+ ),
+ Some("@abc".to_string())
+ );
+ assert_eq!(
+ infer_name_from_url(&Url::parse("file:///@abc.ts").unwrap()),
+ Some("@abc".to_string())
+ );
+ assert_eq!(
+ infer_name_from_url(&Url::parse("file:///@abc/cli.ts").unwrap()),
+ Some("@abc".to_string())
+ );
}
#[test]