diff -r 28ee14bbe0ab -r 48f85579cc4c pidgin/gtkutils.c --- a/pidgin/gtkutils.c Mon Jan 27 17:34:21 2014 +0530 +++ b/pidgin/gtkutils.c Wed Jan 29 00:28:08 2014 +0530 @@ -3205,33 +3205,28 @@ return TRUE; } +/** + * @param filename The path to a file. Specifically this is the link target + * from a link in an IM window with the leading "file://" removed. + */ static void -file_open_uri(GtkWebView *webview, const char *uri) +open_file(GtkWebView *webview, const char *filename) { /* Copied from gtkft.c:open_button_cb */ #ifdef _WIN32 /* If using Win32... */ int code; - if (purple_str_has_prefix(uri, "file://")) - { - gchar *escaped = g_shell_quote(uri); - gchar *param = g_strconcat("/select,\"", uri, "\"", NULL); - wchar_t *wc_param = g_utf8_to_utf16(param, -1, NULL, NULL, NULL); - - code = (int)ShellExecuteW(NULL, L"OPEN", L"explorer.exe", wc_param, NULL, SW_NORMAL); - - g_free(wc_param); - g_free(param); - g_free(escaped); - } else { - wchar_t *wc_filename = g_utf8_to_utf16( - uri, -1, NULL, NULL, NULL); - - code = (int)ShellExecuteW(NULL, NULL, wc_filename, NULL, NULL, - SW_SHOW); - - g_free(wc_filename); - } + /* Escape URI by replacing double-quote with 2 double-quotes. */ + gchar *escaped = purple_strreplace(filename, "\"", "\"\""); + gchar *param = g_strconcat("/select,\"", escaped, "\"", NULL); + wchar_t *wc_param = g_utf8_to_utf16(param, -1, NULL, NULL, NULL); + + /* TODO: Better to use SHOpenFolderAndSelectItems()? */ + code = (int)ShellExecuteW(NULL, L"OPEN", L"explorer.exe", wc_param, NULL, SW_NORMAL); + + g_free(wc_param); + g_free(param); + g_free(escaped); if (code == SE_ERR_ASSOCINCOMPLETE || code == SE_ERR_NOASSOC) { @@ -3243,7 +3238,8 @@ { purple_notify_error(webview, NULL, _("An error occurred while opening the file."), NULL, NULL); - purple_debug_warning("gtkutils", "filename: %s; code: %d\n", uri, code); + purple_debug_warning("gtkutils", "filename: %s; code: %d\n", + filename, code); } #else char *command = NULL; @@ -3252,15 +3248,15 @@ if (purple_running_gnome()) { - char *escaped = g_shell_quote(uri); + char *escaped = g_shell_quote(filename); command = g_strdup_printf("gnome-open %s", escaped); g_free(escaped); } else if (purple_running_kde()) { - char *escaped = g_shell_quote(uri); - - if (purple_str_has_suffix(uri, ".desktop")) + char *escaped = g_shell_quote(filename); + + if (purple_str_has_suffix(filename, ".desktop")) command = g_strdup_printf("kfmclient openURL %s 'text/plain'", escaped); else command = g_strdup_printf("kfmclient openURL %s", escaped); @@ -3268,7 +3264,7 @@ } else { - purple_notify_uri(NULL, uri); + purple_notify_uri(NULL, filename); return; } @@ -3278,7 +3274,7 @@ if (!g_spawn_command_line_sync(command, NULL, NULL, &exit_status, &error)) { tmp = g_strdup_printf(_("Error launching %s: %s"), - uri, error->message); + filename, error->message); purple_notify_error(webview, NULL, _("Unable to open file."), tmp, NULL); g_free(tmp); g_error_free(error); @@ -3299,7 +3295,8 @@ static gboolean file_clicked_cb(GtkWebView *webview, const char *uri) { - file_open_uri(webview, uri + FILELINKSIZE); + /* Strip "file://" from the URI. */ + open_file(webview, uri + FILELINKSIZE); return TRUE; } @@ -3307,7 +3304,7 @@ open_containing_cb(GtkWebView *webview, const char *uri) { char *dir = g_path_get_dirname(uri + FILELINKSIZE); - file_open_uri(webview, dir); + open_file(webview, dir); g_free(dir); return TRUE; }