7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException
authorchegar
Fri, 11 Mar 2011 13:50:09 +0000
changeset 8778 f2ef7d12277f
parent 8777 0e560a0b734d
child 8779 d84abc7b455f
7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException Reviewed-by: alanb, michaelm
jdk/src/share/classes/java/net/URI.java
jdk/test/java/net/URI/Test.java
--- a/jdk/src/share/classes/java/net/URI.java	Fri Mar 11 09:57:13 2011 +0000
+++ b/jdk/src/share/classes/java/net/URI.java	Fri Mar 11 13:50:09 2011 +0000
@@ -1829,21 +1829,23 @@
         } else if (authority != null) {
             sb.append("//");
             if (authority.startsWith("[")) {
+                // authority should (but may not) contain an embedded IPv6 address
                 int end = authority.indexOf("]");
-                if (end != -1 && authority.indexOf(":")!=-1) {
-                    String doquote, dontquote;
+                String doquote = authority, dontquote = "";
+                if (end != -1 && authority.indexOf(":") != -1) {
+                    // the authority contains an IPv6 address
                     if (end == authority.length()) {
                         dontquote = authority;
                         doquote = "";
                     } else {
-                        dontquote = authority.substring(0,end+1);
-                        doquote = authority.substring(end+1);
+                        dontquote = authority.substring(0 , end + 1);
+                        doquote = authority.substring(end + 1);
                     }
-                    sb.append (dontquote);
-                    sb.append(quote(doquote,
+                }
+                sb.append(dontquote);
+                sb.append(quote(doquote,
                             L_REG_NAME | L_SERVER,
                             H_REG_NAME | H_SERVER));
-                }
             } else {
                 sb.append(quote(authority,
                             L_REG_NAME | L_SERVER,
--- a/jdk/test/java/net/URI/Test.java	Fri Mar 11 09:57:13 2011 +0000
+++ b/jdk/test/java/net/URI/Test.java	Fri Mar 11 13:50:09 2011 +0000
@@ -23,7 +23,7 @@
 
 /* @test
  * @summary Unit test for java.net.URI
- * @bug 4464135 4505046 4503239 4438319 4991359 4866303
+ * @bug 4464135 4505046 4503239 4438319 4991359 4866303 7023363
  * @author Mark Reinhold
  */
 
@@ -1050,6 +1050,13 @@
         test("http://1.2.3.4.5").psa().x().z();
         test("http://[1.2.3.4:5]").x().z();
         test("http://1:2:3:4:5:6:7:8").psa().x().z();
+        test("http://[1.2.3.4]/").x().z();
+        test("http://[1.2.3.4/").x().z();
+        test("http://[foo]/").x().z();
+        test("http://[foo/").x().z();
+        test("s", "[foo]", "/", null, null).x().z();
+        test("s", "[foo", "/", null, null).x().z();
+        test("s", "[::foo", "/", null, null).x().z();
 
         // Test hostnames that might initially look like IPv4 addresses