Skip to content

Commit 6712c4d

Browse files
committed
fix: handle quoted arguments in shell-exec on macOS
Use shlex::split to properly parse shell-style quoted arguments when spawning commands on macOS. Previously, args were split on whitespace without respecting quotes, causing commands like `shell-exec open -a "Microsoft Outlook"` to fail because the quoted app name was split into separate arguments. Fixes #1337
1 parent 5709ad0 commit 6712c4d

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ image = "0.25"
2929
serde = { workspace = true }
3030
serde_json = { workspace = true }
3131
serde_yaml = "0.9"
32+
shlex = "1.3"
3233
shell-util = "0.0"
3334
tokio = { workspace = true }
3435
tokio-tungstenite = { workspace = true }

packages/wm/src/commands/general/shell_exec.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ use wm_platform::DispatcherExtWindows;
99

1010
use crate::wm_state::WmState;
1111

12+
/// Splits a shell argument string respecting single and double quotes.
13+
/// Returns `None` if the string contains unmatched quotes.
14+
#[cfg(target_os = "macos")]
15+
fn split_shell_args(args: &str) -> Option<Vec<String>> {
16+
shlex::split(args)
17+
}
18+
1219
pub fn shell_exec(
1320
command: &str,
1421
// LINT: `hide_window` is only used on Windows.
@@ -30,9 +37,11 @@ pub fn shell_exec(
3037
let result = {
3138
#[cfg(target_os = "macos")]
3239
{
40+
let parsed_args = split_shell_args(&args)
41+
.unwrap_or_else(|| args.split_whitespace().map(String::from).collect());
3342
Shell::spawn(
3443
&program,
35-
args.split_whitespace(),
44+
parsed_args,
3645
&CommandOptions::default(),
3746
)
3847
}

0 commit comments

Comments
 (0)