Bug 429546 - [Browsers] org.eclipse.ui.internal.browser.ExternalBrowserInstance.openUrl() which also has "-ingognito" does a toLower on URL string;
Summary: [Browsers] org.eclipse.ui.internal.browser.ExternalBrowserInstance.openUrl() ...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3.2   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.5 M7   Edit
Assignee: Tomasz Zarna CLA
QA Contact: Brian de Alwis CLA
URL:
Whiteboard:
Keywords: bugday, greatfix, helpwanted
Depends on: 405942
Blocks: 463949
  Show dependency tree
 
Reported: 2014-03-04 04:39 EST by Ovidiu Buligan CLA
Modified: 2015-04-28 11:50 EDT (History)
11 users (show)

See Also:


Attachments
mylyn/context/zip (32.34 KB, application/octet-stream)
2015-04-07 07:33 EDT, Tomasz Zarna CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ovidiu Buligan CLA 2014-03-04 04:39:59 EST
Didn't find the 'org.eclipse.ui.browser' project so I reported the bug here.
Creating an external browser instance with parameters (ex: -incognito ) and then using that external browser instance to open a certain url converts the url to loercase . Url's are case sensitive so not all url's work.

The problem is because of some changes last year to java Runtime.exec() which should accept an array of a command and arguments  (each argument in it's own array cell) . 
In the code it concatenates the parameters and url's so when cmd reaches:

  process = Runtime.getRuntime().exec(cmd); 

It contains an arrray containing two cells [browser_executable, -incognito +URL ]
It should be 3.
Comment 1 Paul Webster CLA 2014-03-04 15:06:18 EST
Please include a sample project or code snippet to show how this is being called.

PW
Comment 2 Toshihiro Izumi CLA 2014-03-06 20:32:56 EST
An example on Windows 8.1, Internet Explorer 11, Eclipse 4.4M5, Java 1.7.0_51

Preferences->General->Web Browser
Select "Use external web browser"
Choose "Internet Explorer"
Edit Parameters -> "-private"

Open any html file by Open With->Web Browser

Result:
Internet Explorer opens Bing with "-private file:/C: ... .html" as searching text

Expected:
Internet Explorer opens file:/C: ... .html in private mode
Comment 3 Ovidiu Buligan CLA 2014-03-07 10:01:38 EST
I suspect the problem is in :

org.eclipse.ui.internal.browser.ExternalBrowserInstance.openURL(URL)

more specifficaly 
this line:
Comment 4 Ovidiu Buligan CLA 2014-03-07 10:03:47 EST
(Continued from previews comment , hit shift enter and posted the comment)
The problem is this line :

String params = WebBrowserUtil.createParameterString(parameters, urlText);

It concatenates the -private (-incognito) with the url parameter . they should be in separate array cells for Runtime.exec() new behavior to work
Comment 5 Paul Webster CLA 2014-03-27 13:43:31 EDT
(In reply to Toshihiro Izumi from comment #2)
> An example on Windows 8.1, Internet Explorer 11, Eclipse 4.4M5, Java 1.7.0_51
> 
> Preferences->General->Web Browser
> Select "Use external web browser"
> Choose "Internet Explorer"
> Edit Parameters -> "-private"
> 
> Open any html file by Open With->Web Browser

OK, thanks. As Ovidiu mentioned, the problem is probably in org.eclipse.ui.internal.browser.ExternalBrowserInstance.openURL(URL).  I can't reproduce on linux, as org.eclipse.ui.internal.browser.browsers.MozillaBrowser.BrowserThread.openBrowser(String, String) tokenizes the string before exec'ing.


See https://wiki.eclipse.org/Platform_UI/How_to_Contribute

PW
Comment 6 Alex Blewitt CLA 2014-05-31 12:33:50 EDT
FWIW the Mac version of this uses 'open' with -a as the application id. Any arguments are currently dropped, but adding --args to the end of the open command will pass arguments through, e.g.

open -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --kiosk
Comment 7 Tomasz Zarna CLA 2015-04-07 07:33:51 EDT
Created attachment 252194 [details]
mylyn/context/zip
Comment 8 Brian de Alwis CLA 2015-04-07 11:23:47 EDT
Opened bug 463949 for Alex's point
Comment 10 Brian de Alwis CLA 2015-04-07 12:56:19 EDT
Thanks Tomasz! Fixed for 4.5 M7
Comment 11 Andrey Loskutov CLA 2015-04-08 00:48:14 EDT
(In reply to Eclipse Genie from comment #9)
> Gerrit change https://git.eclipse.org/r/45270 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/
> ?id=cdb1728544d0cd7429ccee12cdd23bf74a037130

This commit caused build failure in the nightly build, see http://download.eclipse.org/eclipse/downloads/drops4/N20150407-2000/compilelogs/plugins/org.eclipse.ua.tests_3.3.800.qualifier/@dot.html

Looks like /browser/org/eclipse/ua/tests/browser/external/TestParameterSubstitution.java still has reference to the old method.
Comment 12 David Williams CLA 2015-04-08 01:13:30 EDT
So ... since caused a build failure ... either the change has to be reverted, or the test code that uses it fixed. 

But, makes me wonder if this is a "change in API"? 

I've only skimmed the comments, but when ever possible, we would want to leave the old version of a method around, marked it @deprecated perhaps even document how it "does not work right" ... but ... to "break" an API at this late point is not good. (And, even, if "internal" non-API, it is not good to remove public methods this late, unless a substantial reason to.) 

Make sense?
Comment 13 Eclipse Genie CLA 2015-04-08 02:14:49 EDT
New Gerrit change created: https://git.eclipse.org/r/45431
Comment 15 Lars Vogel CLA 2015-04-08 02:16:44 EDT
(In reply to David Williams from comment #12)
> So ... since caused a build failure ... either the change has to be
> reverted, or the test code that uses it fixed. 

Test fixed (I hope)

> But, makes me wonder if this is a "change in API"? 

The package name contains internal so I think we should be fine here, IMHO this is not an API change.
Comment 16 Markus Keller CLA 2015-04-08 08:50:58 EDT
String#replaceAll(..) uses regex replacement and would need proper escaping. Please revert that code to use substring(..) and string concatenation.

The code from comment 9 leads to exceptions like this:

Exception in thread "Thread-4" java.lang.IndexOutOfBoundsException: No group 1
	at java.util.regex.Matcher.start(Matcher.java:375)
	at java.util.regex.Matcher.appendReplacement(Matcher.java:880)
	at java.util.regex.Matcher.replaceAll(Matcher.java:955)
	at java.lang.String.replaceAll(String.java:2210)
	at org.eclipse.ui.internal.browser.WebBrowserUtil.createParameterArray(WebBrowserUtil.java:369)
	at org.eclipse.ui.internal.browser.browsers.MozillaBrowser$BrowserThread.run(MozillaBrowser.java:172)

Steps:
- Prefs > Web Browser: Select Firefox as external web browser and set parameters to "-url %URL%"
- restart Eclipse (bug 464153)
- try to open a file called about$1.html
Comment 17 Markus Keller CLA 2015-04-08 08:51:40 EDT
.
Comment 18 Brian de Alwis CLA 2015-04-08 09:48:47 EDT
Reverted from String.replaceAll().  Sorry for the associated breakage.
Comment 19 Tomasz Zarna CLA 2015-04-08 14:53:16 EDT
(In reply to Lars Vogel from comment #15)
> Test fixed (I hope)

Thanks Lars.

(In reply to Brian de Alwis from comment #18)
> Reverted from String.replaceAll().

Thanks Brian.
Comment 20 David Williams CLA 2015-04-08 15:20:48 EDT
(In reply to Lars Vogel from comment #15)

> The package name contains internal so I think we should be fine here, IMHO
> this is not an API change.

I am not saying you are wrong (and you probably are not) but besides our "API rules" which we are strict about "not breaking", there are some methods, in "internal" packages that are in wide spread use that have sort of become defacto APIs ... and IMHO, we should be "friendly" and not break those either unless there is a substantial reason to.  

I know it's hard to know for sure which are in wide spread use, and which are not, but, just wanted to remind you of our friendly nature. :) 

In this case, was there an API that "does the same thing" and the Help system tests just wasn't using it? Or, is there no official API for "open URL"? I know WTP is a project that opens lots of URLs and I don't know what methods they use, or if they use APIs or not. 

So, I've added Chuck and Carl, in case they can arrange for someone to take an for an "early look". 

Just my 2 cents. Again, not saying you wrong, just encouraging everyone to use care in changing public methods.
Comment 21 Eclipse Genie CLA 2015-04-08 15:35:01 EDT
New Gerrit change created: https://git.eclipse.org/r/45494
Comment 23 Brian de Alwis CLA 2015-04-08 16:19:44 EDT
Tomasz restored the old method.
Comment 24 Lars Vogel CLA 2015-04-10 04:19:54 EDT
Looks like my adjustment of the tests is not correct, it causes test failures. Tomasz, can you have a look at decided if we should revert the test of the now deprecated method or if you want to adjust the tests?
Comment 25 Eclipse Genie CLA 2015-04-10 09:28:34 EDT
New Gerrit change created: https://git.eclipse.org/r/45640
Comment 26 Brian de Alwis CLA 2015-04-10 09:30:29 EDT
The fix for the UA Browser Tests wasn't correct as the return value of #createParameterArray() is different from #createParameterString() (array vs string).  Since we've restored #createParameterArray() I've reverted the test change back to what was there previously.
Comment 27 Brian de Alwis CLA 2015-04-10 09:43:31 EDT
Pushed up a better fix that tests both the #createParameterString() and #createParameterArray() variants.  We should move these tests to org.eclipse.ui.tests at some point?
Comment 29 Brian de Alwis CLA 2015-04-10 09:54:08 EDT
Marking as fixed.  Hoping for the last time!
Comment 30 Lars Vogel CLA 2015-04-10 10:04:54 EDT
(In reply to Brian de Alwis from comment #27)
> Pushed up a better fix that tests both the #createParameterString() and
> #createParameterArray() variants.  We should move these tests to
> org.eclipse.ui.tests at some point?

+1, the move makes sense to avoid future cross dependencies. 

Thanks for the fix.
Comment 31 Tomasz Zarna CLA 2015-04-13 00:34:00 EDT
(In reply to Lars Vogel from comment #30)
> +1, the move makes sense to avoid future cross dependencies. 

See bug 464474.
Comment 32 Brian de Alwis CLA 2015-04-28 11:50:18 EDT
Verified in I20150428-0800.