BUG: Fix escaping of more characters on Windows shells.

This commit is contained in:
Brad King 2008-04-30 15:58:45 -04:00
parent 637596a157
commit 16ec04c2a7
2 changed files with 31 additions and 20 deletions

View File

@ -74,6 +74,13 @@ static int kwsysSystem_Shell__CharNeedsQuotesOnUnix(char c)
(c == '*') || (c == '^') || (c == '\\')); (c == '*') || (c == '^') || (c == '\\'));
} }
/*--------------------------------------------------------------------------*/
static int kwsysSystem_Shell__CharNeedsQuotesOnWindows(char c)
{
return ((c == '\'') || (c == '#') || (c == '&') ||
(c == '<') || (c == '>') || (c == '|') || (c == '^'));
}
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
static int kwsysSystem_Shell__CharNeedsQuotes(char c, int isUnix, int flags) static int kwsysSystem_Shell__CharNeedsQuotes(char c, int isUnix, int flags)
{ {
@ -99,16 +106,12 @@ static int kwsysSystem_Shell__CharNeedsQuotes(char c, int isUnix, int flags)
} }
else else
{ {
/* On Windows single-quotes must be escaped in some make /* On Windows several special characters need quotes to preserve them. */
environments, such as in mingw32-make. */ if(kwsysSystem_Shell__CharNeedsQuotesOnWindows(c))
if(flags & kwsysSystem_Shell_Flag_Make)
{
if(c == '\'')
{ {
return 1; return 1;
} }
} }
}
return 0; return 0;
} }

View File

@ -207,14 +207,12 @@ ADD_CUSTOM_COMMAND(OUTPUT gen_redirect.c
############################################################################## ##############################################################################
# Test non-trivial command line arguments in custom commands. # Test non-trivial command line arguments in custom commands.
SET(EXPECTED_ARGUMENTS) SET(EXPECTED_ARGUMENTS)
# TODO: Check shell operators < > << >> | 2>&1 1>&2 &> ! &
SET(CHECK_ARGS SET(CHECK_ARGS
c:/posix/path c:/posix/path
c:\\windows\\path c:\\windows\\path
'single-quotes' 'single-quotes'
single'quote single'quote
\"double-quotes\" \"double-quotes\"
double\"quote
"\\;semi-colons\\;" "\\;semi-colons\\;"
"semi\\;colon" "semi\\;colon"
`back-ticks` `back-ticks`
@ -225,15 +223,15 @@ SET(CHECK_ARGS
{curly} {curly}
{lcurly} {lcurly}
rcurly} rcurly}
#<angle> # angle-brackets are inconsistent on windows right now <angle>
#<langle <langle
#rangle> rangle>
[square] [square]
[lsquare # these have funny behavior due to special cases for [lsquare # these have funny behavior due to special cases for
rsquare] # windows registry value names in list expansion rsquare] # windows registry value names in list expansion
$dollar-signs$ $dollar-signs$
dollar$sign dollar$sign
&ampersands& &ampersands&x # Borland make does not like trailing ampersand
one&ampersand one&ampersand
@two-ats@ @two-ats@
one@at one@at
@ -268,7 +266,6 @@ SET(CHECK_ARGS
"'single quotes with space'" "'single quotes with space'"
"single'quote with space" "single'quote with space"
"\"double-quotes with space\"" "\"double-quotes with space\""
"double\"quote with space"
"\\;semi-colons w s\\;" "\\;semi-colons w s\\;"
"semi\\;colon w s" "semi\\;colon w s"
"`back-ticks` w s" "`back-ticks` w s"
@ -279,9 +276,9 @@ SET(CHECK_ARGS
"{curly} w s" "{curly} w s"
"{lcurly w s" "{lcurly w s"
"rcurly} w s" "rcurly} w s"
#"<angle> w s" # angle-brackets are inconsistent on windows right now "<angle> w s"
#"<langle w s" "<langle w s"
#"rangle> w s" "rangle> w s"
"[square] w s" "[square] w s"
"[lsquare w s" # these have funny behavior due to special cases for "[lsquare w s" # these have funny behavior due to special cases for
"rsquare] w s" # windows registry value names in list expansion "rsquare] w s" # windows registry value names in list expansion
@ -316,15 +313,26 @@ SET(CHECK_ARGS
"#two-pounds# w s" "#two-pounds# w s"
"one#pound w s" "one#pound w s"
~ ` ! @ \# $ % ^ & _ - + = : "\;" \" ' , . ? "(" ")" { } [] ~ ` ! @ \# $ % ^ & _ - + = : "\;" \" ' , . ? "(" ")" { } []
# | < > << >> &> 2>&1 1>&2
# \\ # Need to test last to avoid ; escape in list.
# # Make tools need help when this is the last argument.
) )
IF(NOT MINGW) IF(NOT MINGW)
# * # MinGW programs on windows always expands the wildcard! # * # MinGW programs on windows always expands the wildcard!
# / # MSys make converts a leading slash to the mingw home directory # / # MSys make converts a leading slash to the mingw home directory
LIST(APPEND CHECK_ARGS * /) LIST(APPEND CHECK_ARGS * /)
ENDIF(NOT MINGW) ENDIF(NOT MINGW)
# The windows command shell does not support a double quote by itself:
# double\"quote
# without messing up quoting of arguments following it.
# Make tools need help with escaping a single backslash
# \
# at the end of a command because they think it is a continuation
# character.
# We now have special cases for shell operators:
# | < > << >> &> 2>&1 1>&2
# to allow custom commands to perform redirection.
FOREACH(arg ${CHECK_ARGS}) FOREACH(arg ${CHECK_ARGS})
SET(ARG "${arg}") SET(ARG "${arg}")
STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ARG "${ARG}") STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ARG "${ARG}")