Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320934

Summary: [Browser] Open in external web browser does not work for file with space or # in path
Product: [Eclipse Project] Platform Reporter: Markus Keller <markus.kell.r>
Component: User AssistanceAssignee: Chris Goldthorpe <cgold>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: cgold, spektom
Version: 3.7   
Target Milestone: 3.7 M7   
Hardware: PC   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 415061    
Attachments:
Description Flags
Patch
none
Better patch
none
Fix 3
none
Fix 4
none
Patch that uses cmdarray when calling exec none

Description Markus Keller CLA 2010-07-26 12:51:27 EDT
I20100720-0800 Linux/GTK

Open in external web browser does not work for file with space in path

- Have "Preferences > General > Web Browser" set to use "Firefox" as external browser (location /usr/bin/firefox, no parameters).
- Open a file from the Package Explorer with a space in the path name (e.g.
"hello world.html").

=> Opens Firefox with multiple tabs, with locations separated at the spaces.
- Works fine with the "Default system web browser".
- Works fine on WinXP.

Looks like the problem is that MozillaBrowser#openURL(URL) does not encode the space character on Linux. The "replace spaces by %20" code looks incomplete anyway. You might want to try "URIUtil.toURI(url2).toASCIIString()" (at all 3 places where you insert "%20").
Comment 1 Chris Goldthorpe CLA 2010-10-14 19:36:26 EDT
Reproduced on Red Hat Linux using I20101012-0800.
Comment 2 Chris Goldthorpe CLA 2010-10-14 19:49:20 EDT
Created attachment 180921 [details]
Patch
Comment 3 Markus Keller CLA 2010-10-15 05:25:36 EDT
Created attachment 180934 [details]
Better patch

Trying to encode the URL yourself is doomed to fail. E.g. I still can't open a file named ab#c.html on Windows. Here's a better fix that encodes the URL using URI#toASCIIString() (in all 3 affected places).
Comment 4 Chris Goldthorpe CLA 2010-10-15 14:19:00 EDT
I agree, your fix is better. Committed to HEAD.
Comment 5 Markus Keller CLA 2011-03-09 16:17:52 EST
I'm going to reopen this, since the fix causes problems in other cases (in I20110308-2000). When I e.g. use "Project > Generate Javadoc..." and choose a folder with spaces as target, then "Navigate > Open Attached Javadoc" doesn't work.

I think real reason for the problems with spaces is in org.eclipse.ui.internal.browser.BrowserLauncher, which calls "file.toFile().toURL()" (twice). A better solution is to use "file.toFile().toURI().toURL()" instead.

File#toURL() is actually broken and has been deprecated in JavaSE 1.6. It looks like URIUtil#toURI(URL) is just meant as a workaround for bad URLs and should be avoided if possible (bug 339422). That would also solve the problem that made me file bug 337479.
Comment 6 Markus Keller CLA 2011-03-09 16:28:08 EST
Created attachment 190796 [details]
Fix 3

Proposed fix on HEAD.

Tested with all browser settings on Windows (7). Needs testing on Linux and Mac.
Comment 7 Markus Keller CLA 2011-03-10 20:19:34 EST
Created attachment 190948 [details]
Fix 4

Grrr, that bug 294650 drives me crazy! Here's the complete patch.
Comment 8 Markus Keller CLA 2011-03-11 04:30:08 EST
Works fine on Cocoa. Only catch is bug 339655, but that was also there before.
Comment 9 Markus Keller CLA 2011-03-11 06:57:55 EST
Also good on GTK. There, fragments are cut away (bug 339671), but that's also nothing new.
Comment 10 Chris Goldthorpe CLA 2011-03-14 12:28:32 EDT
It tests out fine for me also with a variety of non alpanumeric characters and non ASCII characters. Patch committed to HEAD.
Comment 11 Michael Spector CLA 2012-01-25 05:21:04 EST
Still happens in 3.7.1:

1. Create a link to firefox, containing whitespace character:

# ln -s firefox "My Browser"

2. Add this Web browser using the preference page.
3. External browser doesn't open.

Please see the attached patch that fixes the problem.
Comment 12 Michael Spector CLA 2012-01-25 05:22:12 EST
Created attachment 210039 [details]
Patch that uses cmdarray when calling exec
Comment 13 Markus Keller CLA 2012-06-20 11:50:48 EDT
Michael, the 3.7.x branch is closed now.

If you still see the problems from comment 11, please open a new bug (also since your problem is different from the subject of this bug).