X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be03c0ec26612a7ab8a9000f455a015c02e05218..24bcaec36746abeeb9e2023d03e3ab4289006fc3:/src/common/cmdline.cpp diff --git a/src/common/cmdline.cpp b/src/common/cmdline.cpp index 2b550d15ec..2c5ea56421 100644 --- a/src/common/cmdline.cpp +++ b/src/common/cmdline.cpp @@ -460,6 +460,8 @@ size_t wxCmdLineParser::GetParamCount() const wxString wxCmdLineParser::GetParam(size_t n) const { + wxCHECK_MSG( n < GetParamCount(), wxEmptyString, _T("invalid param index") ); + return m_data->m_parameters[n]; } @@ -986,6 +988,28 @@ static wxString GetTypeName(wxCmdLineParamType type) // global functions // ---------------------------------------------------------------------------- +/* + This function is mainly used under Windows (as under Unix we always get the + command line arguments as agrc/argv anyhow) and so it tries to handle the + Windows path names (separated by backslashes) correctly. For this it only + considers that a backslash may be used to escape another backslash (but + normally this is _not_ needed) or a quote but nothing else. + + In particular, to pass a single argument containing a space to the program + it should be quoted: + + myprog.exe foo bar -> argc = 3, argv[1] = "foo", argv[2] = "bar" + myprog.exe "foo bar" -> argc = 2, argv[1] = "foo bar" + + To pass an argument containing spaces and quotes, the latter should be + escaped with a backslash: + + myprog.exe "foo \"bar\"" -> argc = 2, argv[1] = "foo "bar"" + + This hopefully matches the conventions used by Explorer/command line + interpreter under Windows. If not, this function should be fixed. + */ + /* static */ wxArrayString wxCmdLineParser::ConvertStringToArgs(const wxChar *p) { @@ -1045,7 +1069,11 @@ wxArrayString wxCmdLineParser::ConvertStringToArgs(const wxChar *p) case _T(' '): case _T('\t'): - if ( isInsideQuotes || isQuotedByBS ) + // we intentionally don't check for preceding backslash + // here as if we allowed it to be used to escape spaces the + // cmd line of the form "foo.exe a:\ c:\bar" wouldn't be + // parsed correctly + if ( isInsideQuotes ) { // preserve it, skip endParam below break;