From: Vadim Zeitlin Date: Tue, 1 Jul 2008 00:05:36 +0000 (+0000) Subject: quote the arguments containing spaces or quotes correctly in wxExecute(char **) overl... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3cdd564fb9d9a982528131689e8f56e5ea946f13?ds=inline quote the arguments containing spaces or quotes correctly in wxExecute(char **) overload (#4115) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54441 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/utilsexc.cpp b/src/msw/utilsexc.cpp index 60fb2164e5..7c085553ed 100644 --- a/src/msw/utilsexc.cpp +++ b/src/msw/utilsexc.cpp @@ -1027,9 +1027,22 @@ long wxExecuteImpl(CharType **argv, int flags, wxProcess *handler) wxString command; command.reserve(1024); + 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("\"", "\\\"", true /* replace all */); + + // and quote any arguments containing the spaces to prevent them from + // being broken down + if ( arg.find_first_of(" \t") == wxString::npos ) + command += arg; + else + command += '\"' + arg + '\"'; + if ( !*argv ) break;