changeset 11300:801eb37fc6c4

6933879: URISyntaxException when non-alphanumeric characters are present in scope_id Reviewed-by: chegar
author kshefov
date Fri, 23 Jan 2015 15:42:06 +0300
parents 76faf72d802f
children 7e88cae22c16
files src/java.base/share/classes/java/net/URI.java test/java/net/URI/Test.java
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/net/URI.java	Fri Jan 23 13:57:02 2015 +0300
+++ b/src/java.base/share/classes/java/net/URI.java	Fri Jan 23 15:42:06 2015 +0300
@@ -2637,6 +2637,11 @@
     private static final long H_URIC_NO_SLASH
         = H_UNRESERVED | H_ESCAPED | highMask(";?:@&=+$,");
 
+    // scope_id = alpha | digit | "_" | "."
+    private static final long L_SCOPE_ID
+        = L_ALPHANUM | lowMask("_.");
+    private static final long H_SCOPE_ID
+        = H_ALPHANUM | highMask("_.");
 
     // -- Escaping and encoding --
 
@@ -3226,7 +3231,7 @@
                         if (r+1 == q) {
                             fail ("scope id expected");
                         }
-                        checkChars (r+1, q, L_ALPHANUM, H_ALPHANUM,
+                        checkChars (r+1, q, L_SCOPE_ID, H_SCOPE_ID,
                                                 "scope id");
                     } else {
                         parseIPv6Reference(p, q);
--- a/test/java/net/URI/Test.java	Fri Jan 23 13:57:02 2015 +0300
+++ b/test/java/net/URI/Test.java	Fri Jan 23 15:42:06 2015 +0300
@@ -24,7 +24,7 @@
 /* @test
  * @summary Unit test for java.net.URI
  * @bug 4464135 4505046 4503239 4438319 4991359 4866303 7023363 7041800
- *      7171415
+ *      7171415 6933879
  * @author Mark Reinhold
  */
 
@@ -1600,6 +1600,7 @@
 
     static void bugs() {
         b6339649();
+        b6933879();
         b8037396();
     }
 
@@ -1614,6 +1615,18 @@
         }
     }
 
+    // 6933879 - check that "." and "_" characters are allowed in IPv6 scope_id.
+    private static void b6933879() {
+        final String HOST = "fe80::c00:16fe:cebe:3214%eth1.12_55";
+        URI uri;
+        try {
+            uri = new URI("http", null, HOST, 10, "/", null, null);
+        } catch (URISyntaxException ex) {
+            throw new AssertionError("Should not happen", ex);
+        }
+        eq("[" + HOST + "]", uri.getHost());
+    }
+
     private static void b8037396() {
 
         // primary checks: