[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-distro-pkg-dev
Subject:    /hg/icedtea-web: PR909: URL is invalid after normalization
From:       smohammad () icedtea ! classpath ! org (smohammad at icedtea ! classpath ! org)
Date:       2012-12-20 20:46:53
Message-ID: hg.95fc28e972ad.1356036413.8643924302249223276 () icedtea ! classpath ! org
[Download RAW message or body]

changeset 95fc28e972ad in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=95fc28e972ad
author: Saad Mohammad <smohammad at redhat.com>
date: Thu Dec 20 15:46:26 2012 -0500

	PR909: URL is invalid after normalization


diffstat:

 ChangeLog                                            |    6 +
 NEWS                                                 |    1 +
 netx/net/sourceforge/jnlp/cache/ResourceTracker.java |  113 ++----------------
 3 files changed, 21 insertions(+), 99 deletions(-)

diffs (168 lines):

diff -r 2b2073cc9a19 -r 95fc28e972ad ChangeLog
--- a/ChangeLog	Thu Dec 20 11:11:05 2012 -0500
+++ b/ChangeLog	Thu Dec 20 15:46:26 2012 -0500
@@ -1,3 +1,9 @@
+2012-12-20  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-12-20  Adam Domurad  <adomurad at redhat.com>
 
 	* plugin/icedteanp/IcedTeaScriptablePluginObject.cc
diff -r 2b2073cc9a19 -r 95fc28e972ad NEWS
--- a/NEWS	Thu Dec 20 11:11:05 2012 -0500
+++ b/NEWS	Thu Dec 20 15:46:26 2012 -0500
@@ -28,6 +28,7 @@
   - PR1161: X509VariableTrustManager does not work correctly with OpenJDK7
   - PR822: Applets fail to load if jars have different signers
   - PR1186: System.getProperty("deployment.user.security.trusted.cacerts") is null
+  - PR909: The Java applet at http://de.gosupermodel.com/games/wardrobegame.jsp \
fails  
 New in release 1.3 (2012-XX-XX):
 * NetX
diff -r 2b2073cc9a19 -r 95fc28e972ad \
                netx/net/sourceforge/jnlp/cache/ResourceTracker.java
--- a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java	Thu Dec 20 11:11:05 2012 \
                -0500
+++ b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java	Thu Dec 20 15:46:26 2012 \
-0500 @@ -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;
     }
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic