@@ -1346,32 +1346,34 @@ PHP_CLI_API int do_php_cli(int argc, char *argv[])
13461346 orig_cp = (php_win32_cp_get_orig ())-> id ;
13471347 /* Embedders supply their own arguments, we mustn't replace them with
13481348 * the ones by the host process command line. */
1349- if (argv_save == __argv ) {
1349+ if (argv_save != __argv ) {
1350+ if (!php_win32_cp_use_unicode ()) {
1351+ /* Custom arguments must be passed as UTF-8, convert to PHP's internal encvodingg. */
1352+ char * * converted_argv = calloc ((size_t ) argc + 1 , sizeof (char * ));
1353+ if (!converted_argv ) {
1354+ exit_status = 1 ;
1355+ goto out ;
1356+ }
1357+ argv = converted_argv ;
1358+ for (int i = 0 ; i < argc ; i ++ ) {
1359+ wchar_t * arg = php_win32_cp_utf8_to_w (argv_save [i ]);
1360+ if (arg ) {
1361+ argv [i ] = php_win32_cp_w_to_any (arg );
1362+ free (arg );
1363+ }
1364+ if (!argv [i ]) {
1365+ fprintf (stderr , "Could not convert command line argument %d.\n" , i );
1366+ exit_status = 1 ;
1367+ goto out ;
1368+ }
1369+ }
1370+ }
1371+ } else {
13501372 /* Ignore the delivered argv and argc, read from W API. This place
13511373 might be too late though, but this is the earliest place ATW
13521374 we can access the internal charset information from PHP. */
13531375 argv_wide = CommandLineToArgvW (GetCommandLineW (), & num_args );
13541376 PHP_WIN32_CP_W_TO_ANY_ARRAY (argv_wide , num_args , argv , argc )
1355- } else if (!php_win32_cp_use_unicode ()) {
1356- /* Custom arguments are UTF-8, regardless of PHP's configured encoding. */
1357- char * * converted_argv = calloc ((size_t ) argc + 1 , sizeof (char * ));
1358- if (!converted_argv ) {
1359- exit_status = 1 ;
1360- goto out ;
1361- }
1362- argv = converted_argv ;
1363- for (int i = 0 ; i < argc ; i ++ ) {
1364- wchar_t * arg = php_win32_cp_utf8_to_w (argv_save [i ]);
1365- if (arg ) {
1366- argv [i ] = php_win32_cp_w_to_any (arg );
1367- free (arg );
1368- }
1369- if (!argv [i ]) {
1370- fprintf (stderr , "Could not convert command line argument %d.\n" , i );
1371- exit_status = 1 ;
1372- goto out ;
1373- }
1374- }
13751377 }
13761378
13771379 SetConsoleCtrlHandler (php_cli_win32_ctrl_handler , TRUE);
0 commit comments