Quote file names with spaces in wxFileType::ExpandCommand().
Add double quotes around the file name inserted into the command to open the file by wxFileType::ExpandCommand() if the file name contains any spaces and if it's not already quoted by the command line itself. While this doesn't completely fix the problem, it does help with opening the files with spaces in their names under Windows and shouldn't do any harm under Unix. Closes #4607. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64655 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -192,22 +192,28 @@ wxString wxFileType::ExpandCommand(const wxString& command,
|
|||||||
{
|
{
|
||||||
bool hasFilename = false;
|
bool hasFilename = false;
|
||||||
|
|
||||||
|
// We consider that only the file names with spaces in them need to be
|
||||||
|
// handled specially. This is not perfect, but this can be done easily
|
||||||
|
// under all platforms while handling the file names with quotes in them,
|
||||||
|
// for example, needs to be done differently.
|
||||||
|
const bool needToQuoteFilename = params.GetFileName().find_first_of(" \t")
|
||||||
|
!= wxString::npos;
|
||||||
|
|
||||||
wxString str;
|
wxString str;
|
||||||
for ( const wxChar *pc = command.c_str(); *pc != wxT('\0'); pc++ ) {
|
for ( const wxChar *pc = command.c_str(); *pc != wxT('\0'); pc++ ) {
|
||||||
if ( *pc == wxT('%') ) {
|
if ( *pc == wxT('%') ) {
|
||||||
switch ( *++pc ) {
|
switch ( *++pc ) {
|
||||||
case wxT('s'):
|
case wxT('s'):
|
||||||
// '%s' expands into file name (quoted because it might
|
// don't quote the file name if it's already quoted: notice
|
||||||
// contain spaces) - except if there are already quotes
|
// that we check for a quote following it and not preceding
|
||||||
// there because otherwise some programs may get confused
|
// it as at least under Windows we can have commands
|
||||||
// by double double quotes
|
// containing "file://%s" (with quotes) in them so the
|
||||||
#if 0
|
// argument may be quoted even if there is no quote
|
||||||
if ( *(pc - 2) == wxT('"') )
|
// directly before "%s" itself
|
||||||
str << params.GetFileName();
|
if ( needToQuoteFilename && pc[1] != '"' )
|
||||||
else
|
|
||||||
str << wxT('"') << params.GetFileName() << wxT('"');
|
str << wxT('"') << params.GetFileName() << wxT('"');
|
||||||
#endif
|
else
|
||||||
str << params.GetFileName();
|
str << params.GetFileName();
|
||||||
hasFilename = true;
|
hasFilename = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -264,8 +270,14 @@ wxString wxFileType::ExpandCommand(const wxString& command,
|
|||||||
#ifdef __UNIX__
|
#ifdef __UNIX__
|
||||||
&& !str.StartsWith(wxT("test "))
|
&& !str.StartsWith(wxT("test "))
|
||||||
#endif // Unix
|
#endif // Unix
|
||||||
) {
|
)
|
||||||
str << wxT(" < '") << params.GetFileName() << wxT('\'');
|
{
|
||||||
|
str << wxT(" < ");
|
||||||
|
if ( needToQuoteFilename )
|
||||||
|
str << '"';
|
||||||
|
str << params.GetFileName();
|
||||||
|
if ( needToQuoteFilename )
|
||||||
|
str << '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
Reference in New Issue
Block a user