cli: Only allow shell-friendly characters in names
This commit is contained in:
parent
376c3caca0
commit
ebee41fbf1
|
|
@ -84,13 +84,21 @@ impl Args for Options {
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
match arg {
|
match arg {
|
||||||
Long("name") if name.is_none() => {
|
Long("name") if name.is_none() => {
|
||||||
let value = parser
|
let value = parser.value()?;
|
||||||
.value()?
|
let value = term::args::string(&value);
|
||||||
.to_str()
|
let allowed = ['-', '_', '.'];
|
||||||
.ok_or(anyhow::anyhow!(
|
|
||||||
"invalid project name specified with `--name`"
|
// Nb. We avoid characters that need to be quoted by shells, such as `$`,
|
||||||
))?
|
// `!` etc., since repository names are used for naming folders during clone.
|
||||||
.to_owned();
|
if !value
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_alphanumeric() || allowed.contains(&c))
|
||||||
|
{
|
||||||
|
anyhow::bail!(
|
||||||
|
"invalid project name specified with `--name`, \
|
||||||
|
only alphanumeric characters, '-', '_' and '.' are allowed"
|
||||||
|
);
|
||||||
|
}
|
||||||
name = Some(value);
|
name = Some(value);
|
||||||
}
|
}
|
||||||
Long("description") if description.is_none() => {
|
Long("description") if description.is_none() => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue