cli: Only allow shell-friendly characters in names

This commit is contained in:
cloudhead 2023-12-11 13:33:05 +01:00
parent 376c3caca0
commit ebee41fbf1
No known key found for this signature in database
1 changed files with 15 additions and 7 deletions

View File

@ -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() => {