changeset 3916:3fdfa11ea5ac

7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException Reviewed-by: alanb, michaelm
author chegar
date Fri, 11 Mar 2011 13:50:09 +0000
parents f4d3033b4b65
children ed87479c96c2
files src/share/classes/java/net/URI.java test/java/net/URI/Test.java
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/URI.java	Fri Mar 11 09:57:13 2011 +0000
+++ b/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/test/java/net/URI/Test.java	Fri Mar 11 09:57:13 2011 +0000
+++ b/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