Hi all,

This commit makes java.net.SocketPermission()'s constructor use
"localhost" when called with an empty hostport argument as mandated
by the spec.  

Cheers,
Gary
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.8476
diff -u -r1.8476 ChangeLog
--- ChangeLog   31 Aug 2006 10:50:56 -0000      1.8476
+++ ChangeLog   31 Aug 2006 12:25:06 -0000
@@ -1,3 +1,11 @@
+2006-08-31  Gary Benson  <[EMAIL PROTECTED]>
+
+       * java/net/SocketPermission.java
+       (maybeBracketIPv6Address): Renamed to processHostport.
+       (processHostport): Also translate "" to "localhost".
+       (setHostPort): Remove special cases for empty hostport and for
+       extra colons in hostport (processHostport handles these now).
+
 2006-08-31  Mark Wielaard  <[EMAIL PROTECTED]>
 
        * javax/swing/text/ZoneView.java (Zone): Make static class.
Index: java/net/SocketPermission.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/SocketPermission.java,v
retrieving revision 1.21
diff -u -r1.21 SocketPermission.java
--- java/net/SocketPermission.java      29 Aug 2006 08:25:15 -0000      1.21
+++ java/net/SocketPermission.java      31 Aug 2006 12:25:06 -0000
@@ -164,21 +164,26 @@
    */
   public SocketPermission(String hostport, String actions)
   {
-    super(maybeBracketIPv6Address(hostport));
+    super(processHostport(hostport));
 
     setHostPort(getName());
     setActions(actions);
   }
 
   /**
-   * IPv6 addresses in the hostport must either be enclosed by
-   * "[" and "]" or be specified in the full uncompressed form.
-   * In the latter case proprietary JVMs will quote the address
-   * with "[" and "]", so we do to.
+   * There are two cases in which hostport needs rewriting before
+   * being passed to the superclass constructor.  If hostport is an
+   * empty string then it is substituted with "localhost".  And if
+   * the host part of hostport is a literal IPv6 address in the full
+   * uncompressed form not enclosed with "[" and "]" then we enclose
+   * it with them.
    */
-  private static String maybeBracketIPv6Address(String hostport)
+  private static String processHostport(String hostport)
   {
-    if (hostport.length() == 0 || hostport.charAt(0) == '[')
+    if (hostport.length() == 0)
+      return "localhost";
+
+    if (hostport.charAt(0) == '[')
       return hostport;
 
     int colons = 0, last_colon = 0;
@@ -221,11 +226,7 @@
   {
     // Split into host and ports
     String ports;
-    if (hostport.length() == 0)
-      {
-       host = ports = "";
-      }
-    else if (hostport.charAt(0) == '[')
+    if (hostport.charAt(0) == '[')
       {
        // host is a bracketed IPv6 address
        int end = hostport.indexOf("]");
@@ -255,8 +256,6 @@
            ports = hostport.substring(sep + 1);
          }
       }
-    if (ports.indexOf(":") != -1)
-      throw new IllegalArgumentException("Unexpected ':'");
 
     // Parse and validate the ports
     if (ports.length() == 0)

Reply via email to