[IsolationSession] A command line that starts with a quote loses its first and last quote
Relevant area(s)
Windows
Brief description of your issue
The IsolationSession backend launches cmd.exe with the arguments /c <commandLine> (src/mxc-sdk/src/backends/isolation_session/common/process_options.rs :: build_process_options) for every run except a PTY run. When the command line starts with a quote and contains more than two quotes, cmd.exe removes the first and the last quote before running it, as cmd /? documents, so a quoted program followed by a quoted argument fails. docs/development/architecture/backends/isolation-session/oneshot.md describes the wrapper as cmd.exe /c "...". The Windows Sandbox guest has the same defect in separate code (#1643).
Steps to reproduce
Start cmd.exe with the arguments /c <commandLine>, as build_process_options does, on Windows 11 with each command line:
"C:\Windows\System32\cmd.exe" /c "echo hello""C:\Program Files\PowerShell\7\pwsh.exe" "--version"
Expected behavior
hello, exit code 0.- The PowerShell version, exit code 0.
Actual behavior
The directory name is invalid., exit code 1.'C:\Program' is not recognized as an internal or external command, operable program or batch file., exit code 1.
Seems like fixing this would involve introducing a rule that people might be working around already.
A generalized solution for this could be wrapping the config's commandLine field in protective quotes before we pass it to cmd.exe internally, so cmd.exe won't touch any quotes from the caller's original command. However, some people may be working around this already by wrapping their commandLines in protective quotes as part of the config construction process. I can't really foresee a way to detect whether a commandLine with " as the first and last character is a fully-quoted command or not within MXC without adding some kind of more complicated command-line parser, which I don't know if we should take on.
Pausing development right now so that we can talk about this potential compatibility issue going forward.
Addressing this issue in two PRs:
The first (#1773) clarifies the current commandLine handling more clearly in the documentation.
The second will be a breaking change to wrap the commandLine in protective quotes, as originally specified in oneshot.md, implemented when breaking changes can be accepted.