harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r521709 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLClassLoader.java test/java/tests/api/java/net/URLClassLoaderTest.java
Date Fri, 23 Mar 2007 12:51:26 GMT
Author: ayza
Date: Fri Mar 23 05:51:25 2007
New Revision: 521709

URL: http://svn.apache.org/viewvc?view=rev&rev=521709
Log:
Fixing encoding / decoding of resource name in URLClassLoader. See HARMONY-3461.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java?view=diff&rev=521709&r1=521708&r2=521709
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLClassLoader.java
Fri Mar 23 05:51:25 2007
@@ -23,6 +23,7 @@
 import java.io.FilePermission;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 import java.security.AccessControlContext;
 import java.security.AccessController;
 import java.security.CodeSource;
@@ -1014,10 +1015,19 @@
     }
 
     private URL targetURL(URL base, String name) throws MalformedURLException {
-        String file = new StringBuffer(base.getFile().length() + name.length())
-                .append(base.getFile()).append(name).toString();
-        return new URL(base.getProtocol(), base.getHost(), base.getPort(),
-                file, null);
+        try {
+            String file = base.getFile() + URIEncoderDecoder.quoteIllegal(name,
+                    "/@" + URI.someLegal);
+
+            return new URL(base.getProtocol(), base.getHost(), base.getPort(),
+                    file, null);
+        } catch (UnsupportedEncodingException e) {
+            MalformedURLException e2 = new MalformedURLException(e.toString());
+            
+            e2.initCause(e);
+            throw e2;
+        }
+        
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java?view=diff&rev=521709&r1=521708&r2=521709
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLClassLoaderTest.java
Fri Mar 23 05:51:25 2007
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.net.URLStreamHandler;
@@ -363,21 +364,28 @@
     public void testFindResource_H3461() throws Exception {
         File userDir = new File(System.getProperty("user.dir"));
         File dir = new File(userDir, "encode#me");
-        File f;
+        File f, f2;
         URLClassLoader loader;
+        URL dirUrl;
         
         if (!dir.exists()) {
             dir.mkdir();
         }
+        dir.deleteOnExit();
+        dirUrl = new URI("file", null, dir.getAbsolutePath() +
+                        File.separator, null).toURL();
+        loader = new URLClassLoader( new URL[] { dirUrl });
+
         f = File.createTempFile("temp", ".dat", dir);
         f.deleteOnExit();
-        dir.deleteOnExit();
-        loader = new URLClassLoader(
-                new URL[] { new URL("file:" + userDir.getAbsolutePath() +
-                        "/encode%23me/") });
+        f2 = File.createTempFile("bad#name#", ".dat", dir);
+        f2.deleteOnExit();
                 
-        assertNotNull("Unable to load resource with problematic name",
+        assertNotNull("Unable to load resource from path with problematic name",
             loader.getResource(f.getName()));
+        assertEquals("URL was not correctly encoded",
+            new URI("file", null, f2.getAbsolutePath(), null).toURL(),    
+            loader.getResource(f2.getName()));
     }
 
     /**



Mime
View raw message