[gnome-text-editor] path: escape paths when expanding



commit 0dd5344b7c3917861d49697967aef74c117a754c
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 5 16:42:19 2022 -0800

    path: escape paths when expanding
    
    We might need to escape things like spaces so that the wordexp() API can
    process them correctly.
    
    Fixes #280

 src/editor-path.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/src/editor-path.c b/src/editor-path.c
index 957eb7d..d468049 100644
--- a/src/editor-path.c
+++ b/src/editor-path.c
@@ -32,13 +32,15 @@ gchar *
 _editor_path_expand (const gchar *path)
 {
   wordexp_t state = { 0 };
-  gchar *ret = NULL;
+  char *escaped = NULL;
+  char *ret = NULL;
   int r;
 
   if (path == NULL)
     return NULL;
 
-  r = wordexp (path, &state, WRDE_NOCMD);
+  escaped = g_shell_quote (path);
+  r = wordexp (escaped, &state, WRDE_NOCMD);
   if (r == 0 && state.we_wordc > 0)
     ret = g_strdup (state.we_wordv [0]);
   wordfree (&state);
@@ -50,6 +52,8 @@ _editor_path_expand (const gchar *path)
       ret = g_build_filename (g_get_home_dir (), freeme, NULL);
     }
 
+  g_free (escaped);
+
   return ret;
 }
 


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