Fix edge cases in argvToCommandLine's argument quoting.

* Quoting is needed for empty arguments (i.e. put double-quotes in the
   command line) and for arguments containing tabs because both spaces and
   tabs can separate arguments.

 * A double-quote in the argument doesn't by itself necessitate quoting.

 * As of this change, argvToCommandLine quotes an argument in the same
   cases as Python's subprocess module.
This commit is contained in:
Ryan Prichard 2012-04-03 01:13:08 -07:00
parent 794b07e526
commit 0dccfd42e1

View File

@ -254,7 +254,10 @@ static std::string argvToCommandLine(const std::vector<std::string> &argv)
if (argIndex > 0)
result.push_back(' ');
const char *arg = argv[argIndex].c_str();
bool quote = strchr(arg, ' ') != NULL || strchr(arg, '\"') != NULL;
const bool quote =
strchr(arg, ' ') != NULL ||
strchr(arg, '\t') != NULL ||
*arg == '\0';
if (quote)
result.push_back('\"');
int bsCount = 0;