diff --git a/glib/tests/spawn-singlethread.c b/glib/tests/spawn-singlethread.c index 909f702fc..15f03a0c7 100644 --- a/glib/tests/spawn-singlethread.c +++ b/glib/tests/spawn-singlethread.c @@ -312,24 +312,40 @@ test_spawn_sync (void) { int tnum = 1; GError *error = NULL; - GPtrArray *argv; - char *arg; + char *arg = g_strdup_printf ("thread %d", tnum); + /* Include arguments with special symbols to test that they are correctly passed to child. + * This is tested on all platforms, but the most prone to failure is win32, + * where args are specially escaped during spawning. + */ + const char * const argv[] = { + echo_prog_path, + arg, + "doublequotes\\\"after\\\\\"\"backslashes", /* this would be special escaped on win32 */ + "\\\"\"doublequotes spaced after backslashes\\\\\"", /* this would be special escaped on win32 */ + "even$$dollars", + "even%%percents", + "even\"\"doublequotes", + "even''singlequotes", + "even\\\\backslashes", + "even//slashes", + "$odd spaced$dollars$", + "%odd spaced%spercents%", + "\"odd spaced\"doublequotes\"", + "'odd spaced'singlequotes'", + "\\odd spaced\\backslashes\\", /* this wasn't handled correctly on win32 in glib <=2.58 */ + "/odd spaced/slashes/", + NULL + }; + char *joined_args_str = g_strjoinv ("", (char**)argv + 1); char *stdout_str; int estatus; - arg = g_strdup_printf ("thread %d", tnum); - - argv = g_ptr_array_new (); - g_ptr_array_add (argv, echo_prog_path); - g_ptr_array_add (argv, arg); - g_ptr_array_add (argv, NULL); - - g_spawn_sync (NULL, (char**)argv->pdata, NULL, 0, NULL, NULL, &stdout_str, NULL, &estatus, &error); + g_spawn_sync (NULL, (char**)argv, NULL, 0, NULL, NULL, &stdout_str, NULL, &estatus, &error); g_assert_no_error (error); - g_assert_cmpstr (arg, ==, stdout_str); + g_assert_cmpstr (joined_args_str, ==, stdout_str); g_free (arg); g_free (stdout_str); - g_ptr_array_free (argv, TRUE); + g_free (joined_args_str); } /* Like test_spawn_sync but uses spawn flags that trigger the optimized