[glib: 1/6] gspawn, tests: check passing special chars in args



commit 387739b0185cfd3e25913b9f486f7356fe53d041
Author: Vasily Galkin <galkin-vv yandex ru>
Date:   Wed Dec 26 23:30:57 2018 +0300

    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'.

 glib/tests/spawn-singlethread.c | 40 ++++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)
---
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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]