From b69b11c40c2eb3fbf77f6b72b4d8fe39340d3d2a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 1 Jul 2008 00:05:36 +0000 Subject: [PATCH] quote the arguments containing spaces or quotes correctly in wxExecute(char **) overload (#4115) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@54441 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/utilsexc.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 3034f9def1..2c56e3fccf 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -114,6 +114,7 @@ wxMSW: - Fix keyboard support in wxSpinCtrl broken in 2.8.8. - Compile fix for WinCE in window.cpp (no VkKeyScan in Windows CE). +- Fix quoting of arguments passed to wxExecute(char **) (briis). wxGTK: diff --git a/src/msw/utilsexc.cpp b/src/msw/utilsexc.cpp index 6fc80fe856..1237c4d429 100644 --- a/src/msw/utilsexc.cpp +++ b/src/msw/utilsexc.cpp @@ -952,9 +952,22 @@ long wxExecute(wxChar **argv, int flags, wxProcess *handler) { wxString command; + wxString arg; for ( ;; ) { - command += *argv++; + arg = *argv++; + + // escape any quotes present in the string to avoid interfering with + // the command line parsing in the child process + arg.Replace(_T("\""), _T("\\\""), true /* replace all */); + + // and quote any arguments containing the spaces to prevent them from + // being broken down + if ( arg.find_first_of(_T(" \t")) == wxString::npos ) + command += arg; + else + command += _T('\"') + arg + _T('\"'); + if ( !*argv ) break;