From e0bbf43ee41f4e9edd3033657fba5147b100345f Mon Sep 17 00:00:00 2001 From: chegar Date: Fri, 11 Mar 2011 13:50:09 +0000 Subject: [PATCH] 7023363: URI("ftp", "[www.abc.com]", "/dir1/dir2", "query", "frag") should throw URISyntaxException Reviewed-by: alanb, michaelm --- src/share/classes/java/net/URI.java | 16 +++++++++------- test/java/net/URI/Test.java | 9 ++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/share/classes/java/net/URI.java b/src/share/classes/java/net/URI.java index 3465e1ab8..d1d9a8718 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 f0bb8da82..3f157ea75 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 -- GitLab