Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
term: Fix editor command with args
cloudhead committed 2 years ago
commit a5212a7a88f845550461b7691337a14ae9643e42
parent ea69168f44b1b5a1cfde6e84def408895f6c0b65
3 files changed +16 -1
modified Cargo.lock
@@ -2595,6 +2595,7 @@ dependencies = [
 "libc",
 "once_cell",
 "pretty_assertions",
+
 "shlex",
 "tempfile",
 "termion 3.0.0",
 "unicode-display-width",
modified radicle-term/Cargo.toml
@@ -17,6 +17,7 @@ anstyle-query = { version = "1.0.0" }
inquire = { version = "0.6.2", default-features = false, features = ["termion", "editor"] }
libc = { version = "0.2" }
once_cell = { version = "1.13" }
+
shlex = { version = "1.1" }
termion = { version = "3" }
unicode-display-width = { version = "0.3.0" }
unicode-segmentation = { version = "1.7.1" }
modified radicle-term/src/editor.rs
@@ -69,6 +69,18 @@ impl Editor {
                "editor not configured: the `EDITOR` environment variable is not set",
            ));
        };
+
        let Some(parts) = shlex::split(cmd.to_string_lossy().as_ref()) else {
+
            return Err(io::Error::new(
+
                io::ErrorKind::InvalidInput,
+
                format!("invalid editor command {cmd:?}"),
+
            ));
+
        };
+
        let Some((program, args)) = parts.split_first() else {
+
            return Err(io::Error::new(
+
                io::ErrorKind::InvalidInput,
+
                format!("invalid editor command {cmd:?}"),
+
            ));
+
        };

        // We duplicate the stderr file descriptor to pass it to the child process, otherwise, if
        // we simply pass the `RawFd` of our stderr, `Command` will close our stderr when the
@@ -84,10 +96,11 @@ impl Editor {
            process::Stdio::from(tty)
        };

-
        process::Command::new(&cmd)
+
        process::Command::new(program)
            .stdout(unsafe { process::Stdio::from_raw_fd(stderr) })
            .stderr(process::Stdio::inherit())
            .stdin(stdin)
+
            .args(args)
            .arg(&self.path)
            .spawn()
            .map_err(|e| {