From 16ec04c2a7ed80fc10cbc731ef3f7646b5fe6b1a Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 30 Apr 2008 15:58:45 -0400 Subject: BUG: Fix escaping of more characters on Windows shells. --- Source/kwsys/System.c | 17 ++++++++++------- Tests/CustomCommand/CMakeLists.txt | 34 +++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Source/kwsys/System.c b/Source/kwsys/System.c index 3908c05..d205c96 100644 --- a/Source/kwsys/System.c +++ b/Source/kwsys/System.c @@ -75,6 +75,13 @@ static int kwsysSystem_Shell__CharNeedsQuotesOnUnix(char 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) { /* On Windows the built-in command shell echo never needs quotes. */ @@ -99,14 +106,10 @@ static int kwsysSystem_Shell__CharNeedsQuotes(char c, int isUnix, int flags) } else { - /* On Windows single-quotes must be escaped in some make - environments, such as in mingw32-make. */ - if(flags & kwsysSystem_Shell_Flag_Make) + /* On Windows several special characters need quotes to preserve them. */ + if(kwsysSystem_Shell__CharNeedsQuotesOnWindows(c)) { - if(c == '\'') - { - return 1; - } + return 1; } } return 0; diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt index 4660e5d..7e9f29c 100644 --- a/Tests/CustomCommand/CMakeLists.txt +++ b/Tests/CustomCommand/CMakeLists.txt @@ -207,14 +207,12 @@ ADD_CUSTOM_COMMAND(OUTPUT gen_redirect.c ############################################################################## # Test non-trivial command line arguments in custom commands. SET(EXPECTED_ARGUMENTS) -# TODO: Check shell operators < > << >> | 2>&1 1>&2 &> ! & SET(CHECK_ARGS c:/posix/path c:\\windows\\path 'single-quotes' single'quote \"double-quotes\" - double\"quote "\\;semi-colons\\;" "semi\\;colon" `back-ticks` @@ -225,15 +223,15 @@ SET(CHECK_ARGS {curly} {lcurly} rcurly} - # # angle-brackets are inconsistent on windows right now - # + + [square] [lsquare # these have funny behavior due to special cases for rsquare] # windows registry value names in list expansion $dollar-signs$ dollar$sign - &ersands& + &ersands&x # Borland make does not like trailing ampersand one&ersand @two-ats@ one@at @@ -268,7 +266,6 @@ SET(CHECK_ARGS "'single quotes with space'" "single'quote with space" "\"double-quotes with space\"" - "double\"quote with space" "\\;semi-colons w s\\;" "semi\\;colon w s" "`back-ticks` w s" @@ -279,9 +276,9 @@ SET(CHECK_ARGS "{curly} w s" "{lcurly w s" "rcurly} w s" - #" w s" # angle-brackets are inconsistent on windows right now - #" w s" + " w s" + " w s" "[square] w s" "[lsquare w s" # these have funny behavior due to special cases for "rsquare] w s" # windows registry value names in list expansion @@ -316,15 +313,26 @@ SET(CHECK_ARGS "#two-pounds# 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) # * # MinGW programs on windows always expands the wildcard! # / # MSys make converts a leading slash to the mingw home directory LIST(APPEND CHECK_ARGS * /) 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}) SET(ARG "${arg}") STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ARG "${ARG}") -- cgit v0.12