diff --git a/src/share/classes/java/net/URI.java b/src/share/classes/java/net/URI.java index 3465e1ab8794ce64725975608b9f71537b230181..d1d9a87189a549d106ef4138b9dc3cf0dabf7301 100644 --- a/src/share/classes/java/net/URI.java +++ b/src/share/classes/java/net/URI.java @@ -1829,21 +1829,23 @@ public final class URI } 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, diff --git a/test/java/net/URI/Test.java b/test/java/net/URI/Test.java index f0bb8da821a9fea81720fa7fb84319b2ee8051ce..3f157ea75610db71c68e4ee54063779dddf29acc 100644 --- a/test/java/net/URI/Test.java +++ b/test/java/net/URI/Test.java @@ -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 @@ public class Test { 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