Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: dmoore on July 30, 2009, 03:45:22 am

Title: mimehandling plugin tweaks
Post by: dmoore on July 30, 2009, 03:45:22 am
"Use Associated App" currently fails for paths with spaces:

Code
Index: src/plugins/defaultmimehandler/defaultmimehandler.cpp
===================================================================
--- src/plugins/defaultmimehandler/defaultmimehandler.cpp (revision 5719)
+++ src/plugins/defaultmimehandler/defaultmimehandler.cpp (working copy)
@@ -301,10 +301,10 @@
         ShellExecute(0, wxString(_T("open")).c_str(), filename.c_str(), 0, 0, SW_SHOW);
         #endif
         #ifdef __WXGTK__
-        wxExecute(wxString::Format(_T("xdg-open %s"), filename.c_str()));
+        wxExecute(wxString::Format(_T("xdg-open \"%s\""), filename.c_str()));
         #endif
         #ifdef __WXMAC__
-        wxExecute(wxString::Format(_T("open %s"), filename.c_str()));
+        wxExecute(wxString::Format(_T("open \"%s\""), filename.c_str()));
         #endif
         return 0;
     }

ok?
Title: Re: mimehandling plugin tweaks
Post by: MortenMacFly on July 30, 2009, 07:13:51 am
ok?
If that is working like that on the MAC and GTK - sure, go ahead.
Title: Re: mimehandling plugin tweaks
Post by: oBFusCATed on July 30, 2009, 10:04:36 am
And what about escaping the double quotes in the filename?
Title: Re: mimehandling plugin tweaks
Post by: dmoore on July 30, 2009, 01:50:40 pm
And what about escaping the double quotes in the filename?

what do we currently use to escape filenames? alternatively, i'll just call the wxExecute variant that takes the argv array directly, which should handle the paths without escaping them.
Title: Re: mimehandling plugin tweaks
Post by: oBFusCATed on July 30, 2009, 03:36:28 pm
I'm not 100% sure, but replacing " with \" in the filename would do the trick, because that is the purpose of the quotes around the file name.
Title: Re: mimehandling plugin tweaks
Post by: dmoore on July 30, 2009, 04:04:29 pm
I'm not 100% sure, but replacing " with \" in the filename would do the trick, because that is the purpose of the quotes around the file name.

Are there other special character corner cases? I'm not happy about hardcoding a filename escaping routine into the plugin (I was pretty sure we already have this code floating around -- maybe in the compiler plugin?).

For now, I think I'm going to test out the argv variant of wxExecute...
Title: Re: mimehandling plugin tweaks
Post by: dmoore on July 31, 2009, 09:04:02 pm
I'm not 100% sure, but replacing " with \" in the filename would do the trick, because that is the purpose of the quotes around the file name.

Are there other special character corner cases? I'm not happy about hardcoding a filename escaping routine into the plugin (I was pretty sure we already have this code floating around -- maybe in the compiler plugin?).

For now, I think I'm going to test out the argv variant of wxExecute...

aargh... the wxExecute variant I was thinking of takes a char **argv -- what encoding is that supposed to be !? Rather than guess, I'll leave it to wxWidgets to sort out and go back to the commandline wxExecute variant...

I see we have a QuoteStringIfNeeded in globals.h but it doesn't substitute \" for already present ". Shall I fix this as surely it breaks on any filenames containing " characters? (I'd like to think that fixing is unecessary, because " should be rare and unsupported on most OSes and something people capable of writing code wouldn't use)

anyway, assuming yes to fix, the current patch is

Code
Index: src/sdk/globals.cpp
===================================================================
--- src/sdk/globals.cpp (revision 5723)
+++ src/sdk/globals.cpp (working copy)
@@ -191,7 +191,10 @@
  bool hasSpace = str.Find(_T(' ')) != -1;
  bool hasParen = !platform::windows && (str.Find(_T('(')) != -1 || str.Find(_T(')')) != -1);
     if (!str.IsEmpty() && str.GetChar(0) != _T('"') && (hasSpace || hasParen))
+    {
+        str.Replace(_T("\""),_T("\\\""));
         str = wxString(_T("\"")) + str + _T("\"");
+    }
 }
 
 wxString EscapeSpaces(const wxString& str)
Index: src/plugins/defaultmimehandler/defaultmimehandler.cpp
===================================================================
--- src/plugins/defaultmimehandler/defaultmimehandler.cpp (revision 5723)
+++ src/plugins/defaultmimehandler/defaultmimehandler.cpp (working copy)
@@ -301,10 +301,14 @@
         ShellExecute(0, wxString(_T("open")).c_str(), filename.c_str(), 0, 0, SW_SHOW);
         #endif
         #ifdef __WXGTK__
-        wxExecute(wxString::Format(_T("xdg-open %s"), filename.c_str()));
+        wxString escaped_filename(filename);
+        QuoteStringIfNeeded(escaped_filename);
+        wxExecute(wxString::Format(_T("xdg-open %s"), escaped_filename.c_str()));
         #endif
         #ifdef __WXMAC__
-        wxExecute(wxString::Format(_T("open %s"), filename.c_str()));
+        wxString escaped_filename(filename);
+        QuoteStringIfNeeded(escaped_filename);
+        wxExecute(wxString::Format(_T("open %s"), escaped_filename.c_str()));
         #endif
         return 0;
     }