mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
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
This commit is contained in:
parent
0cd05d7377
commit
2c96f64fa7
1 changed files with 29 additions and 1 deletions
|
@ -135,7 +135,17 @@ pub fn infer_name_from_url(url: &Url) -> Option<String> {
|
||||||
stem = parent_name.to_string_lossy().to_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)
|
Some(stem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,6 +489,24 @@ mod tests {
|
||||||
),
|
),
|
||||||
Some("abc".to_string())
|
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]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue