BUG: Windows_ShellArgument: need to escape if the string contains one of a set of special characters as well as spaces. Moved test for needing escapes to a separate method kwsysSystemWindowsShellArgumentNeedsEscape.
This commit is contained in:
parent
f0050269ea
commit
d5d8687d16
@ -22,6 +22,25 @@
|
|||||||
|
|
||||||
#include <string.h> /* strlen */
|
#include <string.h> /* strlen */
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
static int kwsysSystemWindowsShellArgumentNeedsEscape(const char* in)
|
||||||
|
{
|
||||||
|
/* Scan the string for characters that need escaping. Note that
|
||||||
|
single quotes seem to need escaping for some windows shell
|
||||||
|
environments (mingw32-make shell for example). Single quotes do
|
||||||
|
not actually need backslash escapes but must be in a
|
||||||
|
double-quoted argument. */
|
||||||
|
const char* c;
|
||||||
|
for(c=in; *c; ++c)
|
||||||
|
{
|
||||||
|
if(*c == ' ' || *c == '\t' || *c == '"' || *c == '\'')
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
int kwsysSystem_Windows_ShellArgumentSize(const char* in)
|
int kwsysSystem_Windows_ShellArgumentSize(const char* in)
|
||||||
{
|
{
|
||||||
@ -29,21 +48,14 @@ int kwsysSystem_Windows_ShellArgumentSize(const char* in)
|
|||||||
either a terminating null or a separating space. */
|
either a terminating null or a separating space. */
|
||||||
int length = (int)strlen(in) + 1;
|
int length = (int)strlen(in) + 1;
|
||||||
|
|
||||||
|
/* String iterator. */
|
||||||
|
const char* c;
|
||||||
|
|
||||||
/* Keep track of how many backslashes have been encountered in a row. */
|
/* Keep track of how many backslashes have been encountered in a row. */
|
||||||
int backslashes = 0;
|
int backslashes = 0;
|
||||||
|
|
||||||
/* Scan the string for spaces. */
|
/* If nothing needs escaping, we do not need any extra length. */
|
||||||
const char* c;
|
if(!kwsysSystemWindowsShellArgumentNeedsEscape(in))
|
||||||
for(c=in; *c; ++c)
|
|
||||||
{
|
|
||||||
if(*c == ' ' || *c == '\t')
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If there are no spaces, we do not need any extra length. */
|
|
||||||
if(!*c)
|
|
||||||
{
|
{
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
@ -84,21 +96,14 @@ int kwsysSystem_Windows_ShellArgumentSize(const char* in)
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
char* kwsysSystem_Windows_ShellArgument(const char* in, char* out)
|
char* kwsysSystem_Windows_ShellArgument(const char* in, char* out)
|
||||||
{
|
{
|
||||||
|
/* String iterator. */
|
||||||
|
const char* c;
|
||||||
|
|
||||||
/* Keep track of how many backslashes have been encountered in a row. */
|
/* Keep track of how many backslashes have been encountered in a row. */
|
||||||
int backslashes = 0;
|
int backslashes = 0;
|
||||||
|
|
||||||
/* Scan the string for spaces. */
|
/* If nothing needs escaping, we can pass the argument verbatim. */
|
||||||
const char* c;
|
if(!kwsysSystemWindowsShellArgumentNeedsEscape(in))
|
||||||
for(c=in; *c; ++c)
|
|
||||||
{
|
|
||||||
if(*c == ' ' || *c == '\t')
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If there are no spaces, we can pass the argument verbatim. */
|
|
||||||
if(!*c)
|
|
||||||
{
|
{
|
||||||
/* Just copy the string. */
|
/* Just copy the string. */
|
||||||
for(c=in; *c; ++c)
|
for(c=in; *c; ++c)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user