Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 339655 - Program#execute(String) broken for file:/ arguments containing #
Summary: Program#execute(String) broken for file:/ arguments containing #
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.7   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 3.7 M7   Edit
Assignee: Lakshmi P Shanmugam CLA
QA Contact: Silenio Quarti CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-11 04:19 EST by Markus Keller CLA
Modified: 2011-04-26 02:48 EDT (History)
1 user (show)

See Also:


Attachments
patch (1.27 KB, patch)
2011-03-14 04:57 EDT, Lakshmi P Shanmugam CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2011-03-11 04:19:18 EST
I20110310-1119 Cocoa

Program#execute(String) is broken for file:/ arguments containing #. When I generate Javadoc and then want to open the Javadoc of a method selected in the editor in the system browser, then # is wrongly escaped before the argument is passed to the browser (resulting in an URL with %23, which is wrong).

Example:

String urlText = "file:/Users/mk/Documents/runtime-New_configuration/javaP/doc/p/A.html#foo()";
Program program = Program.findProgram("html");
program.execute(urlText);

The problems is in org.eclipse.swt.program.Program.getURL(String). If I add

    || lowercaseName.startsWith ("file:/")

to the condition, then it works. And I can still open files with interesting names like "a,b#&c   [%23].html".
Comment 1 Markus Keller CLA 2011-03-11 07:00:40 EST
I filed bug 339671 for a similar problem on GTK (there, the fragment is cut away, which is also wrong, but not as bad as the wrong escaping).

On Windows 7, the fragment is passed to the browser as expected.
Comment 2 Lakshmi P Shanmugam CLA 2011-03-11 07:23:15 EST
Looks like # is a valid character for filename on Mac. In that case I think we should escape # when it is part of the filename and shouldn't escape only when it is used as an anchor.
Comment 3 Markus Keller CLA 2011-03-11 08:43:07 EST
> Looks like # is a valid character for filename on Mac. In that case I think we
> should escape # when it is part of the filename and shouldn't escape only when
> it is used as an anchor.

The difference should be whether the passed argument is a plain path to a file or if it's a file:/ URL.

In file:/ URLs, any special character in the file name should already be escaped in the string you get, so for valid URLs, there's no need to modify any part of the URL.
Comment 4 Lakshmi P Shanmugam CLA 2011-03-14 04:57:16 EDT
Created attachment 191088 [details]
patch
Comment 5 Lakshmi P Shanmugam CLA 2011-03-14 13:22:20 EDT
Patch adds a check for file:/
Silenio, can you please review the patch?
Comment 6 Silenio Quarti CLA 2011-03-14 16:02:54 EDT
Looks good.
Comment 7 Silenio Quarti CLA 2011-03-14 16:03:58 EDT
One question: Why it is not "file://" instead of "file:/"?
Comment 8 Lakshmi P Shanmugam CLA 2011-03-15 07:26:49 EDT
(In reply to comment #7)
> One question: Why it is not "file://" instead of "file:/"?

file:/path seems to be valid and work same as file:///path. The browser (I tried with Safari & Firefox) takes file URL as file:/<path> and changes it to file:///<path>. NSWorkspace.openURLs() too opens this URL.
Comment 9 Lakshmi P Shanmugam CLA 2011-03-15 08:18:12 EDT
Thanks Silenio.
Fixed in HEAD > 20110315