harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r375380 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URL.java test/java/org/apache/harmony/tests/java/net/AllTests.java test/java/org/apache/harmony/tests/java/net/URLTest.java
Date Mon, 06 Feb 2006 21:30:29 GMT
Author: tellison
Date: Mon Feb  6 13:30:26 2006
New Revision: 375380

URL: http://svn.apache.org/viewcvs?rev=375380&view=rev
Log:
Fix for HARMONY-60 (java.net.URL.getHost() must return the IPv6 address enclosed in square
brackets)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/URLTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java?rev=375380&r1=375379&r2=375380&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URL.java
Mon Feb  6 13:30:26 2006
@@ -382,15 +382,25 @@
 			throw new MalformedURLException(com.ibm.oti.util.Msg.getString(
 					"K0325", port)); //$NON-NLS-1$
 
+		if (host != null && host.indexOf(":") != -1 && host.charAt(0) != '[') {
+			host = "[" + host + "]";
+		}
+
+		this.protocol = protocol;
+		this.host = host;
+		this.port = port;
+
 		// Set the fields from the arguments. Handle the case where the
 		// passed in "file" includes both a file and a ref part.
 		int index = -1;
 		index = file.indexOf("#", file.lastIndexOf("/"));
-		if (index >= 0)
-			set(protocol, host, port, file.substring(0, index), file
-					.substring(index + 1));
-		else
-			set(protocol, host, port, file, null);
+		if (index >= 0) {
+			this.file = file.substring(0, index);
+			ref = file.substring(index + 1);
+		} else {
+			this.file = file;
+		}
+		fixURL(false);
 
 		// Set the stream handler for the URL either to the handler
 		// argument if it was specified, or to the default for the
@@ -408,18 +418,20 @@
 		}
 	}
 
-	void fixURL() {
+	void fixURL(boolean fixHost) {
 		int index;
 		if (host != null && host.length() > 0) {
 			authority = host;
 			if (port != -1)
 				authority = authority + ":" + port;
 		}
-		if (host != null && (index = host.lastIndexOf('@')) > -1) {
-			userInfo = host.substring(0, index);
-			host = host.substring(index + 1);
-		} else {
-			userInfo = null;
+		if (fixHost) {
+			if (host != null && (index = host.lastIndexOf('@')) > -1) {
+				userInfo = host.substring(0, index);
+				host = host.substring(index + 1);
+			} else {
+				userInfo = null;
+			}
 		}
 		if (file != null && (index = file.indexOf('?')) > -1) {
 			query = file.substring(index + 1);
@@ -458,7 +470,7 @@
 		this.port = port;
 		this.ref = ref;
 		hashCode = 0;
-		fixURL();
+		fixURL(true);
 	}
 
 	/**
@@ -655,7 +667,7 @@
 		try {
 			stream.defaultReadObject();
 			if (host != null && authority == null)
-				fixURL();
+				fixURL(true);
 			else if (authority != null) {
 				int index;
 				if ((index = authority.lastIndexOf('@')) > -1)

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java?rev=375380&r1=375379&r2=375380&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/AllTests.java
Mon Feb  6 13:30:26 2006
@@ -30,6 +30,7 @@
 		//$JUnit-BEGIN$
 		suite.addTestSuite(URLEncoderTest.class);
 		suite.addTestSuite(InetAddressTest.class);
+		suite.addTestSuite(URLTest.class);
 		suite.addTestSuite(URITest.class);
 		//$JUnit-END$
 		return suite;

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/URLTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/URLTest.java?rev=375380&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/URLTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/net/URLTest.java
Mon Feb  6 13:30:26 2006
@@ -0,0 +1,47 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.net;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class URLTest extends TestCase {
+
+	/**
+	 * @tests java.net.URL#getHost()
+	 */
+	public void test_getHost() throws MalformedURLException {
+		// Regression for HARMONY-60
+		String ipv6Host = "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210";
+		URL url = new URL("http", ipv6Host, -1, "myfile");
+		assertEquals(("[" + ipv6Host + "]"), url.getHost());
+	}
+	
+	/**
+	 * @tests java.net.URL#URL(java.lang.String, java.lang.String, java.lang.String)
+	 */
+	public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_String() throws
MalformedURLException {
+		// Strange behavior in reference, the hostname contains a ':' so it gets wrapped in '[',
']'
+		URL testURL = new URL("http", "www.apache.org:8080", "test.html#anch");
+		assertEquals("Assert 0: wrong protocol", "http", testURL.getProtocol());
+		assertEquals("Assert 1: wrong host", "[www.apache.org:8080]", testURL.getHost());
+		assertEquals("Assert 2: wrong port", -1, testURL.getPort());
+		assertEquals("Assert 3: wrong file", "test.html", testURL.getFile());
+		assertEquals("Assert 4: wrong anchor", "anch", testURL.getRef());
+	}
+}



Mime
View raw message