[RFC][icedtea-web]: Fix PR909 - The Java applet at http://de.gosupermodel.com/games/wardrobegame.jsp fails
Jiri Vanek
jvanek at redhat.com
Tue Oct 23 02:04:43 PDT 2012
On 09/27/2012 12:21 AM, Saad Mohammad wrote:
> Hello,
>
> I have taken a look into URI.encode() and it seems to be doing the percent
> encoding correctly. Please take a look at my patch and let me know if you have
> any objections to this way of 'normalizing' an URL.
Hi!
Looks much better:)
There is unit test for this behaviour in tests/netx/unit/net/sourceforge/jnlp/cache/ResourceTrackerTest.java
a) ensure it is passing with your fix*
b) add unit test with @bug which is testing your new behaviour (focused on 909 simulation)
* I'm not sure how your patch is behaving when unexpected (encoded/decoded to expected decoded/encoded) (lines 52-64 of your patch) state of coding is delivered. If your fix pass above test, then it should be ok.
As far as I tested it, you are failing for item 1 an 3 in unittest:(
For 1 it is clear failure - try eg "http://localhost:44321/gg%2Ffgg%15fdgfd%45fdg" where it is better to see, for 2, you can remove this test.
The failure (1) is hard to explain. Just from quick check - it looks like url and uri are making different encding/decoding. Please, investigate on it.
Otherwise I have no objection against code and logic.
Than you for fixing it.
J.
ps: ALWAYS run unit-test (and reproducers) BEFORE and AFTER fix and compare results. Every difference must make you more suspecting!
>
> Thanks!
>
> ChangeLog:
>
> 2012-09-26 Saad Mohammad<smohammad at redhat.com>
>
> Fix PR909 - URL is invalid after normalization.
> * netx/net/sourceforge/jnlp/cache/ResourceTracker.java (normalizeUrl):
> Converts the URL to an URI object which handles all percent encodings.
>
>
>
> -- Cheers, Saad Mohammad
>
>
> patch0-7.patch
>
>
> diff --git a/ChangeLog b/ChangeLog
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,9 @@
> +2012-09-26 Saad Mohammad<smohammad at redhat.com>
> +
> + Fix PR909 - URL is invalid after normalization.
> + * netx/net/sourceforge/jnlp/cache/ResourceTracker.java (normalizeUrl):
> + Converts the URL to an URI object which handles all percent encodings.
> +
> 2012-09-25 Jiri Vanek<jvanek at redhat.com>
>
> Added rules listeners
> diff --git a/NEWS b/NEWS
> --- a/NEWS
> +++ b/NEWS
> @@ -18,6 +18,7 @@
> - PR1049: Extension jnlp's signed jar with the content of only META-INF/* is considered
> - PR955: regression: SweetHome3D fails to run
> - PR1161: X509VariableTrustManager does not work correctly with OpenJDK7
> + - PR909: The Java applet athttp://de.gosupermodel.com/games/wardrobegame.jsp fails
>
> New in release 1.3 (2012-XX-XX):
> * NetX
> diff --git a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java
> --- a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java
> +++ b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java
> @@ -27,10 +27,11 @@
> import java.io.UnsupportedEncodingException;
> import java.net.HttpURLConnection;
> import java.net.MalformedURLException;
> +import java.net.URI;
> +import java.net.URISyntaxException;
> import java.net.URL;
> import java.net.URLConnection;
> import java.net.URLDecoder;
> -import java.net.URLEncoder;
> import java.security.AccessController;
> import java.security.PrivilegedAction;
> import java.util.ArrayList;
> @@ -1143,115 +1144,29 @@
> }
> };
>
> - private static String normalizeChunk(String base, boolean debug) throws UnsupportedEncodingException {
> - if (base == null) {
> - return base;
> - }
> - if ("".equals(base)) {
> - return base;
> - }
> - String result = base;
> - String ssE = URLDecoder.decode(base, UTF8);
> - // System.out.println("*" + base + "*");
> - // System.out.println("-" + ssE + "-");
> - if (base.equals(ssE)) {
> - result = URLEncoder.encode(base, UTF8);
> - if (debug) {
> - System.out.println(base + " chunk needs to be encoded => " + result);
> - }
> - } else {
> - if (debug) {
> - System.out.println(base + " chunk already encoded");
> - }
> - }
> - return result;
> - }
> -
> - public static URL normalizeUrl(URL u, boolean debug) throws MalformedURLException, UnsupportedEncodingException {
> + public static URL normalizeUrl(URL u, boolean debug) throws MalformedURLException, UnsupportedEncodingException, URISyntaxException {
> if (u == null) {
> return null;
> }
> String protocol = u.getProtocol();
> +
> if (protocol == null || "file".equals(protocol)) {
> return u;
> }
> - String file = u.getPath();
> - if (file == null) {
> +
> + if (u.getPath() == null) {
> return u;
> }
> - String host = u.getHost();
> - String ref = u.getRef();
> - int port = u.getPort();
> - String query = u.getQuery();
> - String[] qq = {};
> - if (query != null) {
> - qq = query.split(QUERY_DELIMITER);
> - }
> - String[] ss = file.split(PATH_DELIMITER);
> - int normalized = 0;
> - if (debug) {
> - System.out.println("normalizing path " + file + " in " + u.toString());
> - }
> - for (int i = 0; i< ss.length; i++) {
> - String base = ss[i];
> - String r = normalizeChunk(base, debug);
> - if (!r.equals(ss[i])) {
> - normalized++;
> - }
> - ss[i] = r;
> - }
> - if (debug) {
> - System.out.println("normalizing query " + query + " in " + u.toString());
> - }
> - for (int i = 0; i< qq.length; i++) {
> - String base = qq[i];
> - String r = normalizeChunk(base, debug);
> - if (!r.equals(qq[i])) {
> - normalized++;
> - }
> - qq[i] = r;
> - }
> - if (normalized == 0) {
> - if (debug) {
> - System.out.println("Nothing was normalized in this url");
> - }
> - return u;
> - } else {
> - if (debug) {
> - System.out.println(normalized + " chunks normalized, rejoining url");
> - }
> - }
> - StringBuilder composed = new StringBuilder("");
> - for (int i = 0; i< ss.length; i++) {
> - String string = ss[i];
> - if (ss.length<= 1 || (string != null&& !"".equals(string))) {
> - composed.append(PATH_DELIMITER_MARK).append(string);
> - }
> - }
> - String composed1 = composed.toString();
> - if (query != null&& !query.trim().equals("")) {
> - composed.append(QUERY_MARK);
> - for (int i = 0; i< qq.length; i++) {
> - String string = qq[i];
> - if ((string != null&& !"".equals(string))) {
> - composed.append(string);
> - if (i != qq.length - 1) {
> - composed.append(QUERY_DELIMITER_MARK);
> - }
> - }
> - }
> - }
> - String composed2 = composed.substring(composed1.length() - 1);
> - if (ref != null&& !ref.trim().equals("")) {
> - composed.append(HREF_MARK).append(ref);
> - }
>
> - URL result = new URL(protocol, host, port, composed.toString());
> + //Decode the URL before encoding
> + URL decodedURL = new URL(URLDecoder.decode(u.toString(), UTF8));
>
> - if (debug) {
> - System.out.println("normalized `" + composed1 + "` and `" + composed2 + "` in " + result.toString());
> - }
> - return result;
> + //Create URI with the decoded URL
> + URI uri = new URI(decodedURL.getProtocol(), null, decodedURL.getHost(), decodedURL.getPort(), decodedURL.getPath(), decodedURL.getQuery(), null);
>
> + //Returns the encoded URL
> + URL encodedURL = new URL(uri.toASCIIString());
> +
> + return encodedURL;
> }
> }
More information about the distro-pkg-dev
mailing list