Fix quoted hook commands on Windows (#33926)

## Why

Windows hook commands whose executable paths contain spaces fail when their
outer quotes are escaped during argument construction.

## What changed

- Pass hook command strings as raw arguments to the default Windows shell.
- Do the same for configured shells that use the case-insensitive `/c` flag,
  while retaining normal argument handling for other shells.

## Testing

Add a Windows regression test that runs a quoted `.cmd` hook from a directory
with spaces through both the default shell and an explicit `COMSPEC /c` shell.

GitOrigin-RevId: 0e7ce44203e01d3823daaaec750c2aeadfcd34b7
This commit is contained in:
Abhinav
2026-07-17 23:24:26 +00:00
committed by copyberry
parent f896ab9f25
commit 3ac476bed2
2 changed files with 80 additions and 0 deletions
@@ -168,9 +168,22 @@ fn build_command(shell: &CommandShell, handler: &ConfiguredHandler) -> Command {
Command::new(&shell.program)
};
if shell.program.is_empty() {
#[cfg(windows)]
command.raw_arg(format!(r#""{}""#, handler.command));
#[cfg(not(windows))]
command.arg(&handler.command);
} else {
command.args(&shell.args);
#[cfg(windows)]
if shell.args.iter().any(|arg| arg.eq_ignore_ascii_case("/c")) {
command.raw_arg(format!(r#""{}""#, handler.command));
} else {
command.arg(&handler.command);
}
#[cfg(not(windows))]
command.arg(&handler.command);
}
command.envs(&handler.env);
@@ -194,3 +207,7 @@ fn default_shell_command() -> Command {
command
}
}
#[cfg(all(test, windows))]
#[path = "command_runner_tests.rs"]
mod tests;