[glib] gio-tool: Do not alter uris before use



commit 796599a705cf49bed28df0b86eb76a38a59b27d0
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Feb 24 15:33:11 2017 +0100

    gio-tool: Do not alter uris before use
    
    Uris may be altered by the following code, which breaks xdg-open:
    file = g_file_new_for_commandline_arg (arg[i])
    uri = g_file_get_uri (file);
    
    Examples of possible uri changes:
    mailto:email -> mailto:///email
    magnet:?xt=urn:hash -> magnet:///?xt=urn:hash
    ssh://user@host -> sftp://user@host
    
    This patch causes that uris aren't preprocessed for locations with
    scheme, however absolute and relative paths are still preprocessed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779182

 gio/gio-tool-open.c |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/gio/gio-tool-open.c b/gio/gio-tool-open.c
index 9f06f4e..f4a1642 100644
--- a/gio/gio-tool-open.c
+++ b/gio/gio-tool-open.c
@@ -146,16 +146,28 @@ handle_open (int argc, char *argv[], gboolean do_help)
   success = TRUE;
   for (i = 1; i < argc; i++)
     {
-      GFile *file;
-      char *uri;
+      char *uri = NULL;
+      char *uri_scheme;
+
+      /* Workaround to handle non-URI locations. We still use the original
+       * location for other cases, because GFile might modify the URI in ways
+       * we don't want. See:
+       * https://bugzilla.gnome.org/show_bug.cgi?id=779182 */
+      uri_scheme = g_uri_parse_scheme (argv[i]);
+      if (!uri_scheme || uri_scheme[0] == '\0')
+        {
+          GFile *file;
 
-      file = g_file_new_for_commandline_arg (argv[i]);
-      uri = g_file_get_uri (file);
-      res = g_app_info_launch_default_for_uri (uri, NULL, &error);
+          file = g_file_new_for_commandline_arg (argv[i]);
+          uri = g_file_get_uri (file);
+          g_object_unref (file);
+        }
+      g_free (uri_scheme);
 
+      res = g_app_info_launch_default_for_uri (uri ? uri : argv[i], NULL, &error);
       if (!res)
        {
-          print_file_error (file, error->message);
+          print_error ("%s: %s", uri ? uri : argv[i], error->message);
          g_clear_error (&error);
          success = FALSE;
        }
@@ -169,7 +181,7 @@ handle_open (int argc, char *argv[], gboolean do_help)
           char *bus_name = NULL;
           char *object_path = NULL;
 
-          if (get_bus_name_and_path_from_uri (uri, &bus_name, &object_path))
+          if (get_bus_name_and_path_from_uri (uri ? uri : argv[i], &bus_name, &object_path))
             {
               GDBusConnection *connection;
               connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
@@ -189,7 +201,6 @@ handle_open (int argc, char *argv[], gboolean do_help)
         }
 #endif
 
-      g_object_unref (file);
       g_free (uri);
     }
 


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