summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorTingPing <tingping@tingping.se>2014-09-07 19:38:18 -0400
committerTingPing <tingping@tingping.se>2014-09-07 19:45:44 -0400
commit5f99d34c3b38324d5c92803884ae811a6550ad20 (patch)
tree0731f1e11c15121c90263662c534df64462b5cc2 /src
parent2aa3eb8cfbf03bb7f56d6b1dba5767fecc0222cd (diff)
Fix opening utf8 urls on OSX
- Escape hostnames with punycode
- Use proper encoding when launching open
Diffstat (limited to 'src')
-rw-r--r--src/fe-gtk/fe-gtk.c87
1 files changed, 59 insertions, 28 deletions
diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c
index 5df37779..004068af 100644
--- a/src/fe-gtk/fe-gtk.c
+++ b/src/fe-gtk/fe-gtk.c
@@ -983,23 +983,75 @@ fe_set_inputbox_contents (session *sess, char *text)
 	}
 }
 
+#ifdef __APPLE__
+static char *
+url_escape_hostname (const char *url)
+{
+    char *host_start, *host_end, *ret, *hostname;
+
+    host_start = strstr (url, "://");
+    if (host_start != NULL)
+    {
+        *host_start = '\0';
+        host_start += 3;
+        host_end = strchr (host_start, '/');
+
+        if (host_end != NULL)
+        {
+            *host_end = '\0';
+            host_end++;
+        }
+
+        hostname = g_hostname_to_ascii (host_start);
+        if (host_end != NULL)
+            ret = g_strdup_printf ("%s://%s/%s", url, hostname, host_end);
+        else
+            ret = g_strdup_printf ("%s://%s", url, hostname);
+
+        g_free (hostname);
+        return ret;
+    }
+
+    return g_strdup (url);
+}
+
+static void
+osx_show_uri (const char *url)
+{
+    char *escaped_url, *encoded_url, *open, *cmd;
+
+    escaped_url = url_escape_hostname (url);
+    encoded_url = g_filename_from_utf8 (escaped_url, -1, NULL, NULL, NULL);
+    if (encoded_url)
+    {
+        open = g_find_program_in_path ("open");
+        cmd = g_strjoin (" ", open, encoded_url, NULL);
+
+        hexchat_exec (cmd);
+
+        g_free (encoded_url);
+        g_free (cmd);
+    }
+
+    g_free (escaped_url);
+}
+
+#endif
+
 static void
 fe_open_url_inner (const char *url)
 {
 #ifdef WIN32
 	ShellExecute (0, "open", url, NULL, NULL, SW_SHOWNORMAL);
-#elif defined __APPLE__
-	/* on Mac you can just 'open http://foo.bar/' */
-	gchar open[512];
-	g_snprintf (open, sizeof(open), "%s %s", g_find_program_in_path ("open"), url, NULL);
-	hexchat_exec (open);
+#elif defined(__APPLE__)
+    osx_show_uri (url);
 #else
 	gtk_show_uri (NULL, url, GDK_CURRENT_TIME, NULL);
 #endif
 }
 
-static void
-fe_open_url_locale (const char *url)
+void
+fe_open_url (const char *url)
 {
 	int url_type = url_check_word (url);
 	char *uri;
@@ -1042,27 +1094,6 @@ fe_open_url_locale (const char *url)
 }
 
 void
-fe_open_url (const char *url)
-{
-	char *loc;
-
-	if (prefs.utf8_locale)
-	{
-		fe_open_url_locale (url);
-		return;
-	}
-
-	/* the OS expects it in "locale" encoding. This makes it work on
-	   unix systems that use ISO-8859-x and Win32. */
-	loc = g_locale_from_utf8 (url, -1, 0, 0, 0);
-	if (loc)
-	{
-		fe_open_url_locale (loc);
-		g_free (loc);
-	}
-}
-
-void
 fe_server_event (server *serv, int type, int arg)
 {
 	GSList *list = sess_list;