r12966 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12965‎ | r12966 | r12967 >
Date:23:50, 6 February 2006
Author:timstarling
Status:old
Tags:
Comment:
Proper windows escaping in wfEscapeShellArg()
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -956,7 +956,28 @@
957957 }
958958
959959 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 . '"';
961982 } else {
962983 $retVal .= escapeshellarg( $arg );
963984 }

Status & tagging log