6773270: java.net.URI fails to escape \u0000
authormichaelm
Fri, 21 May 2010 07:29:48 +0100
changeset 5612 c0d1673e1ca6
parent 5611 b4ef86f105ec
child 5613 1146efa21514
6773270: java.net.URI fails to escape \u0000 Summary: check for \u0000 Reviewed-by: alanb
jdk/src/share/classes/java/net/URI.java
jdk/test/java/net/URI/Test.java
--- a/jdk/src/share/classes/java/net/URI.java	Thu May 20 13:57:58 2010 -0700
+++ b/jdk/src/share/classes/java/net/URI.java	Fri May 21 07:29:48 2010 +0100
@@ -2491,6 +2491,8 @@
 
     // Tell whether the given character is permitted by the given mask pair
     private static boolean match(char c, long lowMask, long highMask) {
+        if (c == 0) // 0 doesn't have a slot in the mask. So, it never matches.
+            return false;
         if (c < 64)
             return ((1L << c) & lowMask) != 0;
         if (c < 128)
--- a/jdk/test/java/net/URI/Test.java	Thu May 20 13:57:58 2010 -0700
+++ b/jdk/test/java/net/URI/Test.java	Fri May 21 07:29:48 2010 +0100
@@ -1091,6 +1091,7 @@
         test("").p("").sp("").z();
 
 
+
         header("Emptiness");
 
         // Components that may be empty
@@ -1321,6 +1322,11 @@
             .sp("//host/foo%20bar/a/b/c/resolve").s("http")
             .pd("/foo bar/a/b/c/resolve").h("host")
             .p("/foo%20bar/a/b/c/resolve").z();
+
+        // 6773270: java.net.URI fails to escape u0000
+        test("s", "a", "/\u0000", null)
+            .s("s").p("/%00").h("a")
+            .ta("s://a/%00").z();
     }