This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, kejxu, paul.moore, steve.dower, tim.golden, zach.ware
Date 2019-07-23.18:22:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1563906143.36.0.411811129903.issue37659@roundup.psfhosted.org>
In-reply-to
Content
The behavior of list2cmdline with double quotes is intentional. It supports passing literal quote characters in the command line for applications that use VC++ argv parsing, WINAPI CommandLineToArgvW, or in general any application that adheres to these rules when parsing its command line [1]. (Not all do -- such as cmd.exe -- in which case we have to pass a custom command line instead of relying on listcmdline.) 

If we have a command line already, then generally the best thing to do in Windows is pass it as is. Don't split it and rebuild it via list2mdline.

The problem I see is using shlex.split in Windows. posix=False doesn't  mean it can handle Windows command lines properly. The shlex module is meant to tokenize a command line like a Unix shell. With posix=False, quote characters aren't stripped out, i.e. it preserves the double quotes in '"spam"'. But with posix=True it's just as wrong for Windows because it tokenizes "'spam & eggs'" as ['spam & eggs']. This is wrong because single quotes generally have no special meaning in Windows command lines (certainly not for CreateProcessW, CommandLineToArgvW, and VC++ argv handling). They should be retained as literal characters. Thus the proper result in Windows is "'spam & eggs'" -> ["'spam", '&', "eggs'"].

[1]: https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments
History
Date User Action Args
2019-07-23 18:22:23eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, kejxu
2019-07-23 18:22:23eryksunsetmessageid: <1563906143.36.0.411811129903.issue37659@roundup.psfhosted.org>
2019-07-23 18:22:23eryksunlinkissue37659 messages
2019-07-23 18:22:22eryksuncreate