BUG: Argument parsers do not always remove double quotes from around an argument that has no spaces.
This commit is contained in:
parent
f22a4a908d
commit
33566642a0
@ -442,11 +442,12 @@ void kwsysProcess_SetCommand(kwsysProcess* cp, char const* const* command)
|
||||
if(command)
|
||||
{
|
||||
/* We need to construct a single string representing the command
|
||||
and its arguments. We will surround each argument with
|
||||
double-quotes so it can contain spaces. We need to escape
|
||||
double-quotes and all backslashes before them. We also need to
|
||||
escape backslashes at the end of an argument because they come
|
||||
before the closing double-quote for the argument. */
|
||||
and its arguments. We will surround each argument containing
|
||||
spaces with double-quotes. Inside a double-quoted argument, we
|
||||
need to escape double-quotes and all backslashes before them.
|
||||
We also need to escape backslashes at the end of an argument
|
||||
because they come before the closing double-quote for the
|
||||
argument. */
|
||||
char* cmd;
|
||||
char const* const* arg;
|
||||
int length = 0;
|
||||
@ -456,11 +457,28 @@ void kwsysProcess_SetCommand(kwsysProcess* cp, char const* const* command)
|
||||
/* Keep track of how many backslashes have been encountered in a
|
||||
row in this argument. */
|
||||
int backslashes = 0;
|
||||
int spaces = 0;
|
||||
const char* c;
|
||||
|
||||
/* Add the length of the argument, plus 3 for the double quotes
|
||||
and space separating the arguments. */
|
||||
length += (int)strlen(*arg) + 3;
|
||||
/* Scan the string for spaces. If there are no spaces, we can
|
||||
pass the argument verbatim. */
|
||||
for(c=*arg; *c; ++c)
|
||||
{
|
||||
if(*c == ' ' || *c == '\t')
|
||||
{
|
||||
spaces = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the length of the argument, plus 1 for the space
|
||||
separating the arguments. */
|
||||
length += (int)strlen(*arg) + 1;
|
||||
|
||||
if(spaces)
|
||||
{
|
||||
/* Add 2 for double quotes since spaces are present. */
|
||||
length += 2;
|
||||
|
||||
/* Scan the string to find characters that need escaping. */
|
||||
for(c=*arg; *c; ++c)
|
||||
@ -489,6 +507,7 @@ void kwsysProcess_SetCommand(kwsysProcess* cp, char const* const* command)
|
||||
/* We need to escape all ending backslashes. */
|
||||
length += backslashes;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate enough space for the command. We do not need an extra
|
||||
byte for the terminating null because we allocated a space for
|
||||
@ -502,14 +521,28 @@ void kwsysProcess_SetCommand(kwsysProcess* cp, char const* const* command)
|
||||
/* Keep track of how many backslashes have been encountered in a
|
||||
row in an argument. */
|
||||
int backslashes = 0;
|
||||
int spaces = 0;
|
||||
const char* c;
|
||||
|
||||
/* Scan the string for spaces. If there are no spaces, we can
|
||||
pass the argument verbatim. */
|
||||
for(c=*arg; *c; ++c)
|
||||
{
|
||||
if(*c == ' ' || *c == '\t')
|
||||
{
|
||||
spaces = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the separating space if this is not the first argument. */
|
||||
if(arg != command)
|
||||
{
|
||||
*cmd++ = ' ';
|
||||
}
|
||||
|
||||
if(spaces)
|
||||
{
|
||||
/* Add the opening double-quote for this argument. */
|
||||
*cmd++ = '"';
|
||||
|
||||
@ -555,12 +588,21 @@ void kwsysProcess_SetCommand(kwsysProcess* cp, char const* const* command)
|
||||
*cmd++ = '\\';
|
||||
}
|
||||
|
||||
/* Add the opening double-quote for this argument. */
|
||||
/* Add the closing double-quote for this argument. */
|
||||
*cmd++ = '"';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No spaces. Add the argument verbatim. */
|
||||
for(c=*arg; *c; ++c)
|
||||
{
|
||||
*cmd++ = *c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the terminating null character to the command line. */
|
||||
*cmd++ = 0;
|
||||
*cmd = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user