harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r487465 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLStreamHandler.java test/java/tests/api/java/net/URLTest.java
Date Fri, 15 Dec 2006 06:39:05 GMT
Author: liangyx
Date: Thu Dec 14 22:39:04 2006
New Revision: 487465

URL: http://svn.apache.org/viewvc?view=rev&rev=487465
Log:
Apply patch for HARMONY-2136 ([classlib][luni] URL.equals() does not resolve an empty hostname
and localhost as the same)

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

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java?view=diff&rev=487465&r1=487464&r2=487465
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
Thu Dec 14 22:39:04 2006
@@ -407,7 +407,7 @@
 	 *         <code>false</code> if the hosts are different
 	 */
 	protected boolean hostsEqual(URL url1, URL url2) {
-        String host1 = url1.getHost(), host2 = url2.getHost();
+        String host1 = getHost(url1), host2 = getHost(url2);
         if (host1 == host2 || (host1 != null && host1.equalsIgnoreCase(host2))) {
             return true;
         }
@@ -451,4 +451,16 @@
         }
 		return p1 == p2;
 	}
+    
+    /*
+     * If the URL host is empty while protocal is file, the host is regarded as
+     * localhost.
+     */
+    private static String getHost(URL url) {
+        String host = url.getHost();
+        if ("file".equals(url.getProtocol()) && "".equals(host)) {
+            host = "localhost";
+        }
+        return host;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java?view=diff&rev=487465&r1=487464&r2=487465
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
Thu Dec 14 22:39:04 2006
@@ -783,6 +783,23 @@
         u = new URL("file", null, -1, "/d:/somedir/");
         u1 = new URL("file:/d:/somedir/");
         assertFalse(u.sameFile(u1));
+        
+        // regression test for Harmony-2136
+        URL url1 = new URL("file:///anyfile");
+        URL url2 = new URL("file://localhost/anyfile");
+        assertTrue(url1.sameFile(url2));
+
+        url1 = new URL("http:///anyfile");
+        url2 = new URL("http://localhost/anyfile");
+        assertFalse(url1.sameFile(url2));
+
+        url1 = new URL("ftp:///anyfile");
+        url2 = new URL("ftp://localhost/anyfile");
+        assertFalse(url1.sameFile(url2));
+
+        url1 = new URL("jar:file:///anyfile.jar!/");
+        url2 = new URL("jar:file://localhost/anyfile.jar!/");
+        assertFalse(url1.sameFile(url2));
     }
 
 	/**



Mime
View raw message