fix(runner): preserve internal quotes in cmd strings on Windows#56
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Command::args(["/C", cmd])runs Rust's MSVCRT-style arg escaping over thecmdstring, 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 likego build -ldflags=\"-s -w\"reached Go with\"-sand-w\"as separate argv entries.raw_arg(Windows-only) so we write the cmd.exe command line literally, and pass/Sso cmd.exe deterministically strips only the outermost pair of quotes — internal quotes survive intact.Resolves #55
Test plan
cargo fmt --checkcargo clippy --all-targets -- -D warningscargo testcmd /c echo -ldflags=\"-s -w\" foonow prints-ldflags=\"-s -w\" foo(one token)echo hello world,echo \"hello world\", multi-arg cmd with quoted args) still execute correctly