Commit 387739b0 authored by Vasily Galkin's avatar Vasily Galkin

gspawn, tests: check passing special chars in args

The existing singlethread g_spawn_sync test is modified and now tests
that special characters in arguments are correctly passed to child.
The test is added before spawn escaping fixing on win32
and covers the case currently broken on win32:
'trailing \ in argument containing space'.
parent 940537be
......@@ -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[] = {
"doublequotes\\\"after\\\\\"\"backslashes", /* this would be special escaped on win32 */
"\\\"\"doublequotes spaced after backslashes\\\\\"", /* this would be special escaped on win32 */
"$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/",
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment