[gnome-builder/gnome-builder-3-20] command-bar: Fix a file path tab autocomplete issue



commit 8fd3919cddda65575374a682572284ed1b98681c
Author: Matthew Leeds <mleeds redhat com>
Date:   Tue Jun 7 12:53:26 2016 -0400

    command-bar: Fix a file path tab autocomplete issue
    
    gb_command_bar_complete expects completions returned by the
    GbCommandVimProvider to include the full prefix that the user typed in,
    not just the filename. Since gb_vim_complete_edit_files returns the
    filename or a relative path from the working directory,
    gb_command_bar_complete reads past the end of a character array. This
    commit makes the completion provider return full file paths to fix this
    issue.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767369

 plugins/command-bar/gb-vim.c |   29 +++++++++++------------------
 1 files changed, 11 insertions(+), 18 deletions(-)
---
diff --git a/plugins/command-bar/gb-vim.c b/plugins/command-bar/gb-vim.c
index 10bd514..f5c7696 100644
--- a/plugins/command-bar/gb-vim.c
+++ b/plugins/command-bar/gb-vim.c
@@ -1292,19 +1292,9 @@ gb_vim_complete_edit_files (GtkWidget *active_widget,
   if (parent != NULL)
     {
       g_autoptr(GFileEnumerator) fe = NULL;
-      g_autofree gchar *relpath = NULL;
       GFileInfo *descendent;
       const gchar *slash;
 
-      relpath = g_file_get_relative_path (workdir, parent);
-
-      if (relpath && g_str_has_prefix (relpath, "./"))
-        {
-          gchar *tmp = relpath;
-          relpath = g_strdup (relpath + 2);
-          g_free (tmp);
-        }
-
 #ifdef IDE_ENABLE_TRACE
       {
         g_autofree gchar *parent_path = g_file_get_path (parent);
@@ -1326,23 +1316,26 @@ gb_vim_complete_edit_files (GtkWidget *active_widget,
       while ((descendent = g_file_enumerator_next_file (fe, NULL, NULL)))
         {
           const gchar *name;
-
           name = g_file_info_get_display_name (descendent);
 
           IDE_TRACE_MSG ("name=%s prefix=%s", name, prefix);
 
           if (name && g_str_has_prefix (name, prefix))
             {
-              gchar *path;
+              gchar *completed_command;
+              const gchar *descendent_name;
+              g_autofree gchar *full_path = NULL;
+              g_autofree gchar *parent_path = NULL;
+
+              parent_path = g_file_get_path (parent);
+              descendent_name = g_file_info_get_name (descendent);
+              full_path = g_build_filename (parent_path, descendent_name, NULL);
 
-              if (relpath)
-                path = g_strdup_printf ("%s %s/%s", command, relpath, name);
-              else
-                path = g_strdup_printf ("%s %s", command, name);
+              completed_command = g_strdup_printf ("%s %s", command, full_path);
 
-              IDE_TRACE_MSG ("edit completion: %s", path);
+              IDE_TRACE_MSG ("edit completion: %s", completed_command);
 
-              g_ptr_array_add (ar, path);
+              g_ptr_array_add (ar, completed_command);
             }
           g_object_unref (descendent);
         }


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