Skip to content

fix(runner): preserve internal quotes in cmd strings on Windows#56

Merged
CalvinAllen merged 1 commit into
mainfrom
fix/runner/preserve-cmd-quotes
May 13, 2026
Merged

fix(runner): preserve internal quotes in cmd strings on Windows#56
CalvinAllen merged 1 commit into
mainfrom
fix/runner/preserve-cmd-quotes

Conversation

@CalvinAllen
Copy link
Copy Markdown
Contributor

Summary

  • On Windows, Command::args(["/C", cmd]) runs Rust's MSVCRT-style arg escaping over the cmd string, converting internal " to \" — but cmd.exe doesn't understand backslash escapes, so the resulting command line is mistokenized by the time the target program receives it. A cmd like go build -ldflags=\"-s -w\" reached Go with \"-s and -w\" as separate argv entries.
  • Switched to raw_arg (Windows-only) so we write the cmd.exe command line literally, and pass /S so cmd.exe deterministically strips only the outermost pair of quotes — internal quotes survive intact.
  • Linux/macOS path is unchanged.

Resolves #55

Test plan

  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test
  • Manual repro on Windows: cmd /c echo -ldflags=\"-s -w\" foo now prints -ldflags=\"-s -w\" foo (one token)
  • Sanity-checked simple cmds (echo hello world, echo \"hello world\", multi-arg cmd with quoted args) still execute correctly

Rust's default Command arg escaping uses MSVCRT backslash-escape rules
that cmd.exe does not understand, so a cmd value like
`go build -ldflags="-s -w"` reached the target program with the inner
quotes mistokenized into separate argv entries.

Use `raw_arg` to write the cmd.exe command line directly and pass `/S`
so cmd.exe deterministically strips only the outermost pair of quotes,
leaving internal quotes intact.
@CalvinAllen CalvinAllen merged commit 42b29b7 into main May 13, 2026
17 checks passed
@CalvinAllen CalvinAllen deleted the fix/runner/preserve-cmd-quotes branch May 13, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

fix(parser): cmd string with internally-quoted args is mistokenized

1 participant