News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

mimehandling plugin tweaks

Started by dmoore, July 30, 2009, 03:45:22 AM

Previous topic - Next topic

dmoore

"Use Associated App" currently fails for paths with spaces:


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?
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

MortenMacFly

Quote from: dmoore on July 30, 2009, 03:45:22 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

oBFusCATed

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!]

dmoore

Quote from: oBFusCATed on July 30, 2009, 10:04:36 AM
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.
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

oBFusCATed

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!]

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.

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...
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

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.

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


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;
     }



Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]