harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r470361 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLStreamHandler.java test/java/tests/api/java/net/URLTest.java
Date Thu, 02 Nov 2006 13:30:00 GMT
Author: pyang
Date: Thu Nov  2 05:29:59 2006
New Revision: 470361

URL: http://svn.apache.org/viewvc?view=rev&rev=470361
Log:
Apply patch for HARMONY-1999([classlib][luni] Bug of java.net.URL.toExternalForm)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java?view=diff&rev=470361&r1=470360&r2=470361
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
Thu Nov  2 05:29:59 2006
@@ -109,6 +109,11 @@
 			int hostIdx = 2, portIdx = -1;
 			port = -1;
 			fileIdx = parseString.indexOf('/', hostIdx);
+            int questionMarkIndex = parseString.indexOf('?', hostIdx);
+            if ((questionMarkIndex != -1)
+                    && ((fileIdx == -1) || (fileIdx > questionMarkIndex))) {
+                fileIdx = questionMarkIndex;
+            }
 			if (fileIdx == -1) {
 				fileIdx = end;
 				// Use default
@@ -165,20 +170,25 @@
 		int fileEnd = (refIdx == -1 ? end : refIdx);
 
 		int queryIdx = parseString.lastIndexOf('?', fileEnd);
-		if (queryIdx > -1) {
-			query = parseString.substring(queryIdx + 1, fileEnd);
-			// Don't inherit file if query is changed
-			if (queryIdx == 0 && file != null) {
-                file = "/";
+        boolean canonicalize = false;
+        if (queryIdx > -1) {
+            query = parseString.substring(queryIdx + 1, fileEnd);
+            if (queryIdx == 0 && file != null) {
+                if (file.equals("")) {
+                    file = "/";
+                } else if (file.startsWith("/")) {
+                    canonicalize = true;
+                }
+                int last = file.lastIndexOf('/') + 1;
+                file = file.substring(0, last);
             }
-			fileEnd = queryIdx;
-		} else
-		// Don't inherit query unless only the ref is changed
-		if (refIdx != 0) {
+            fileEnd = queryIdx;
+        } else
+        // Don't inherit query unless only the ref is changed
+        if (refIdx != 0) {
             query = null;
         }
 
-		boolean canonicalize = false;
 		if (fileIdx > -1) {
 			if (fileIdx < end && parseString.charAt(fileIdx) == '/') {
                 file = parseString.substring(fileIdx, fileEnd);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java?view=diff&rev=470361&r1=470360&r2=470361
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
Thu Nov  2 05:29:59 2006
@@ -1256,21 +1256,25 @@
             // Expected NullPointerException
         }
     }
-
-	/**
-	 * Sets up the fixture, for example, open a network connection. This method
-	 * is called before a test is executed.
-	 */
-	protected void setUp() {
-	}
-
-	/**
-	 * Tears down the fixture, for example, close a network connection. This
-	 * method is called after a test is executed.
-	 */
-	protected void tearDown() {
-	}
 	
+    public void test_toExternalForm_Absolute() throws MalformedURLException {
+        String strURL = "http://localhost?name=value";
+        URL url = new URL(strURL);
+        assertEquals(strURL, url.toExternalForm());
+        
+        strURL = "http://localhost?name=value/age=12";
+        url = new URL(strURL);
+        assertEquals(strURL, url.toExternalForm());
+    }
+
+    public void test_toExternalForm_Relative() throws MalformedURLException {
+        String strURL = "http://a/b/c/d;p?q";
+        String ref = "?y";
+        URL url = new URL(new URL(strURL), ref);
+        assertEquals("http://a/b/c/?y", url.toExternalForm());
+        
+    } 
+    
 	static class MockProxySelector extends ProxySelector {
 
 		public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {



Mime
View raw message