Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
mimehandling plugin tweaks
dmoore:
--- Quote from: 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.
--- End quote ---
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...
dmoore:
--- Quote from: dmoore on July 30, 2009, 04:04:29 pm ---
--- Quote from: 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.
--- End quote ---
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...
--- End quote ---
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;
}
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version