@@ -1014,7 +1014,7 @@ char *mingw_getcwd(char *pointer, int len)
1014
1014
* See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
1015
1015
* (Parsing C++ Command-Line Arguments)
1016
1016
*/
1017
- static const char * quote_arg (const char * arg )
1017
+ static const char * quote_arg_msvc (const char * arg )
1018
1018
{
1019
1019
/* count chars to quote */
1020
1020
int len = 0 , n = 0 ;
@@ -1069,6 +1069,37 @@ static const char *quote_arg(const char *arg)
1069
1069
return q ;
1070
1070
}
1071
1071
1072
+ #include "quote.h"
1073
+
1074
+ static const char * quote_arg_msys2 (const char * arg )
1075
+ {
1076
+ struct strbuf buf = STRBUF_INIT ;
1077
+ const char * p2 = arg , * p ;
1078
+
1079
+ for (p = arg ; * p ; p ++ ) {
1080
+ int ws = isspace (* p );
1081
+ if (!ws && * p != '\\' && * p != '"' && * p != '{' )
1082
+ continue ;
1083
+ if (!buf .len )
1084
+ strbuf_addch (& buf , '"' );
1085
+ if (p != p2 )
1086
+ strbuf_add (& buf , p2 , p - p2 );
1087
+ if (!ws && * p != '{' )
1088
+ strbuf_addch (& buf , '\\' );
1089
+ p2 = p ;
1090
+ }
1091
+
1092
+ if (p == arg )
1093
+ strbuf_addch (& buf , '"' );
1094
+ else if (!buf .len )
1095
+ return arg ;
1096
+ else
1097
+ strbuf_add (& buf , p2 , p - p2 ),
1098
+
1099
+ strbuf_addch (& buf , '"' );
1100
+ return strbuf_detach (& buf , 0 );
1101
+ }
1102
+
1072
1103
static const char * parse_interpreter (const char * cmd )
1073
1104
{
1074
1105
static char buf [100 ];
@@ -1300,6 +1331,34 @@ struct pinfo_t {
1300
1331
static struct pinfo_t * pinfo = NULL ;
1301
1332
CRITICAL_SECTION pinfo_cs ;
1302
1333
1334
+ static int is_msys2_sh (const char * cmd )
1335
+ {
1336
+ if (cmd && !strcmp (cmd , "sh" )) {
1337
+ static int ret = -1 ;
1338
+ char * p ;
1339
+
1340
+ if (ret >= 0 )
1341
+ return ret ;
1342
+
1343
+ p = path_lookup (cmd , 0 );
1344
+ if (!p )
1345
+ ret = 0 ;
1346
+ else {
1347
+ size_t len = strlen (p );
1348
+ ret = len > 15 &&
1349
+ is_dir_sep (p [len - 15 ]) &&
1350
+ !strncasecmp (p + len - 14 , "usr" , 3 ) &&
1351
+ is_dir_sep (p [len - 11 ]) &&
1352
+ !strncasecmp (p + len - 10 , "bin" , 3 ) &&
1353
+ is_dir_sep (p [len - 7 ]) &&
1354
+ !strcasecmp (p + len - 6 , "sh.exe" );
1355
+ free (p );
1356
+ }
1357
+ return ret ;
1358
+ }
1359
+ return 0 ;
1360
+ }
1361
+
1303
1362
static pid_t mingw_spawnve_fd (const char * cmd , const char * * argv , char * * deltaenv ,
1304
1363
const char * dir ,
1305
1364
int prepend_cmd , int fhin , int fhout , int fherr )
@@ -1311,6 +1370,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1311
1370
unsigned flags = CREATE_UNICODE_ENVIRONMENT ;
1312
1371
BOOL ret ;
1313
1372
HANDLE cons ;
1373
+ const char * (* quote_arg )(const char * arg ) =
1374
+ is_msys2_sh (* argv ) ? quote_arg_msys2 : quote_arg_msvc ;
1314
1375
1315
1376
do_unset_environment_variables ();
1316
1377
0 commit comments