Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion rust/crates/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5151,7 +5151,9 @@ fn detect_powershell_shell() -> std::io::Result<&'static str> {
fn command_exists(command: &str) -> bool {
std::process::Command::new("sh")
.arg("-c")
.arg(format!("command -v {command} >/dev/null 2>&1"))
.arg("command -v \"$1\" >/dev/null 2>&1")
.arg("--")
.arg(command)
.status()
Comment on lines 5151 to 5157
.map(|status| status.success())
.unwrap_or(false)
Expand Down Expand Up @@ -8583,4 +8585,13 @@ printf 'pwsh:%s' "$1"
.into_bytes()
}
}

#[test]
fn test_command_exists() {
assert!(super::command_exists("ls") || super::command_exists("dir"));
assert!(!super::command_exists("ls; echo injected"));
assert!(!super::command_exists(
"this_command_should_not_exist_12345"
));
}
}
Loading