Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -956,7 +956,28 @@ |
957 | 957 | } |
958 | 958 | |
959 | 959 | if ( wfIsWindows() ) { |
960 | | - $retVal .= '"' . str_replace( '"','\"', $arg ) . '"'; |
| 960 | + // Escaping for an MSVC-style command line parser |
| 961 | + // Ref: http://mailman.lyra.org/pipermail/scite-interest/2002-March/000436.html |
| 962 | + // Double the backslashes before any double quotes. Escape the double quotes. |
| 963 | + $tokens = preg_split( '/(\\\\*")/', $arg, -1, PREG_SPLIT_DELIM_CAPTURE ); |
| 964 | + $arg = ''; |
| 965 | + $delim = false; |
| 966 | + foreach ( $tokens as $token ) { |
| 967 | + if ( $delim ) { |
| 968 | + $arg .= str_replace( '\\', '\\\\', substr( $token, 0, -1 ) ) . '\\"'; |
| 969 | + } else { |
| 970 | + $arg .= $token; |
| 971 | + } |
| 972 | + $delim = !$delim; |
| 973 | + } |
| 974 | + // Double the backslashes before the end of the string, because |
| 975 | + // we will soon add a quote |
| 976 | + if ( preg_match( '/^(.*?)(\\\\+)$/', $arg, $m ) ) { |
| 977 | + $arg = $m[1] . str_replace( '\\', '\\\\', $m[2] ); |
| 978 | + } |
| 979 | + |
| 980 | + // Add surrounding quotes |
| 981 | + $retVal .= '"' . $arg . '"'; |
961 | 982 | } else { |
962 | 983 | $retVal .= escapeshellarg( $arg ); |
963 | 984 | } |