[Xfce4-commits] <xfce-utils:master> Only try a selection of strings in exo-open (bug #7200).

Nick Schermer noreply at xfce.org
Fri Jun 17 20:26:02 CEST 2011


Updating branch refs/heads/master
         to 008a2e323998478a275e31b0eb5aeeab9ec761bc (commit)
       from 59777e36f47eeaac0e5a524425bb25bd10d58d5f (commit)

commit 008a2e323998478a275e31b0eb5aeeab9ec761bc
Author: Nick Schermer <nick at xfce.org>
Date:   Fri Jun 17 19:59:40 2011 +0200

    Only try a selection of strings in exo-open (bug #7200).
    
    Only to strings that look like uris, paths, www or email
    addresses in exo-open.

 xfrun/xfrun-dialog.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/xfrun/xfrun-dialog.c b/xfrun/xfrun-dialog.c
index cb14011..c7f83ef 100644
--- a/xfrun/xfrun-dialog.c
+++ b/xfrun/xfrun-dialog.c
@@ -470,6 +470,24 @@ xfrun_add_to_history(const gchar *command,
     g_strfreev(lines);
 }
 
+static gboolean
+exo_str_looks_like_an_uri (const gchar *str)
+{
+  const gchar *s = str;
+
+  /* <scheme> starts with an alpha character */
+  if (g_ascii_isalpha (*s))
+    {
+      /* <scheme> continues with (alpha | digit | "+" | "-" | ".")* */
+      for (++s; g_ascii_isalnum (*s) || *s == '+' || *s == '-' || *s == '.'; ++s);
+
+      /* <scheme> must be followed by ":" */
+      return (*s == ':');
+    }
+
+  return FALSE;
+}
+
 static void
 xfrun_spawn_child_setup(gpointer data)
 {
@@ -542,7 +560,11 @@ xfrun_run_clicked(GtkWidget *widget,
         gchar    *primary;
         gboolean  exo_opened = FALSE;
 
-        if(!in_terminal) {
+        if(!in_terminal
+            && (exo_str_looks_like_an_uri (cmdline)
+                || g_path_is_absolute (cmdline)
+                || g_str_has_prefix (cmdline, "www.")
+                || strstr (cmdline, "@") != NULL)) {
             /* Try to open with exo-open (for files, folders, uris...) */
             gchar       **exo_argv = NULL;
             const gchar  *exo_open;
@@ -581,7 +603,7 @@ xfrun_run_clicked(GtkWidget *widget,
                 if(error)
                     g_error_free(error);
             }
-        }else {
+        } else {
             primary = g_strdup_printf(_("The command \"%s\" failed to run:"),
                                      cmdline);
             xfce_message_dialog(GTK_WINDOW(dialog), _("Run Error"),



More information about the Xfce4-commits mailing list