Author Topic: mimehandling plugin tweaks  (Read 4696 times)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
mimehandling plugin tweaks
« on: July 30, 2009, 03:45:22 am »
"Use Associated App" currently fails for paths with spaces:

Code: [Select]
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?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9595
Re: mimehandling plugin tweaks
« Reply #1 on: July 30, 2009, 07:13:51 am »
ok?
If that is working like that on the MAC and GTK - sure, go ahead.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12683
    • Travis build status
Re: mimehandling plugin tweaks
« Reply #2 on: July 30, 2009, 10:04:36 am »
And what about escaping the double quotes in the filename?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: mimehandling plugin tweaks
« Reply #3 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12683
    • Travis build status
Re: mimehandling plugin tweaks
« Reply #4 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: mimehandling plugin tweaks
« Reply #5 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...

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: mimehandling plugin tweaks
« Reply #6 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: [Select]
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;
     }