From 5e7db7c0f1b6060c83ba4b9452bb6fc549331926 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Sat, 18 Feb 2017 10:17:42 -0800 Subject: [PATCH] Fix wxLaunchDefault{Application,Browser}() for arguments containing spaces See #16581 --- src/unix/utilsx11.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/unix/utilsx11.cpp b/src/unix/utilsx11.cpp index cb2f04344a..a588325de4 100644 --- a/src/unix/utilsx11.cpp +++ b/src/unix/utilsx11.cpp @@ -2660,7 +2660,11 @@ bool wxLaunchDefaultApplication(const wxString& document, int flags) if ( wxGetEnv("PATH", &path) && wxFindFileInPath(&xdg_open, path, "xdg-open") ) { - if ( wxExecute(xdg_open + " " + document) ) + const char* argv[3]; + argv[0] = xdg_open.fn_str(); + argv[1] = document.fn_str(); + argv[2] = NULL; + if (wxExecute(argv)) return true; } @@ -2687,6 +2691,10 @@ wxDoLaunchDefaultBrowser(const wxLaunchBrowserParams& params) #endif // GTK_CHECK_VERSION(2,14,0) #endif // __WXGTK__ + const char* argv[4]; + argv[1] = params.GetPathOrURL().fn_str(); + argv[2] = NULL; + // Our best best is to use xdg-open from freedesktop.org cross-desktop // compatibility suite xdg-utils // (see http://portland.freedesktop.org/wiki/) -- this is installed on @@ -2697,7 +2705,8 @@ wxDoLaunchDefaultBrowser(const wxLaunchBrowserParams& params) if ( wxGetEnv("PATH", &path) && wxFindFileInPath(&xdg_open, path, "xdg-open") ) { - if ( wxExecute(xdg_open + " " + params.GetPathOrURL()) ) + argv[0] = xdg_open.fn_str(); + if (wxExecute(argv)) return true; } @@ -2715,16 +2724,19 @@ wxDoLaunchDefaultBrowser(const wxLaunchBrowserParams& params) output, errors, wxEXEC_NODISABLE ); if (res >= 0 && errors.GetCount() == 0) { - wxString cmd = output[0]; - cmd << wxT(' ') << params.GetPathOrURL(); - if (wxExecute(cmd)) + argv[0] = output[0].fn_str(); + if (wxExecute(argv)) return true; } } else if (desktop == wxT("KDE")) { // kfmclient directly opens the given URL - if (wxExecute(wxT("kfmclient openURL ") + params.GetPathOrURL())) + argv[2] = argv[1]; + argv[0] = "kfmclient"; + argv[1] = "openURL"; + argv[3] = NULL; + if (wxExecute(argv)) return true; }