Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Only allow shell-friendly characters in names
cloudhead committed 2 years ago
commit ebee41fbf12255b2b9699c9fb68bebf90553e9f0
parent 376c3caca0fd46cf260a6ad6e336e197f6994d6f
1 file changed +15 -7
modified radicle-cli/src/commands/init.rs
@@ -84,13 +84,21 @@ impl Args for Options {
        while let Some(arg) = parser.next()? {
            match arg {
                Long("name") if name.is_none() => {
-
                    let value = parser
-
                        .value()?
-
                        .to_str()
-
                        .ok_or(anyhow::anyhow!(
-
                            "invalid project name specified with `--name`"
-
                        ))?
-
                        .to_owned();
+
                    let value = parser.value()?;
+
                    let value = term::args::string(&value);
+
                    let allowed = ['-', '_', '.'];
+

+
                    // Nb. We avoid characters that need to be quoted by shells, such as `$`,
+
                    // `!` etc., since repository names are used for naming folders during clone.
+
                    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);
                }
                Long("description") if description.is_none() => {