--- hsqldb/src/org/hsqldb/DatabaseURL.java	2006-01-07 11:01:24.000000000 -0500
+++ fred/src/org/hsqldb/DatabaseURL.java	2010-01-05 14:00:19.000000000 -0500
@@ -126,7 +126,7 @@
         }
 
         String  type = null;
-        String  host;
+        String  host = null;
         int     port = 0;
         String  database;
         String  path;
@@ -189,12 +189,23 @@
 
         if (isNetwork) {
             int slashpos = url.indexOf('/', pos);
+            // slashpos is the TRAILING (optional) slash, which separates
+            // either host or port from path.
 
             if (slashpos < pos || slashpos > semicolpos) {
                 slashpos = semicolpos;
             }
 
-            int colonpos = url.indexOf(':', pos);
+            if (urlImage.charAt(pos) == '[') {
+                // Literal IPv6 address
+                int closeIpv6 = urlImage.indexOf(']', pos + 1);
+                if (closeIpv6 <= pos || closeIpv6 >= slashpos)
+                    return null;  // Malformatted Ipv6 addr
+                host = urlImage.substring(pos + 1, closeIpv6);
+            }
+
+            int colonpos = url.indexOf(':',
+                    (host == null) ? pos : pos + 2 + host.length());
 
             if (colonpos < pos || colonpos > slashpos) {
                 colonpos = slashpos;
@@ -207,9 +218,15 @@
                 }
             }
 
-            host = urlImage.substring(pos, colonpos);
+            if (host == null) {
+                // Non-IPv6 literal
+                host = urlImage.substring(pos, colonpos);
+            }
 
             int secondslashpos = url.lastIndexOf('/', semicolpos);
+            // Despite the name, this is for the LAST slash, not the
+            // second pos.  (It's the 2nd that we use, but that fact
+            // is of no consequence).
 
             if (secondslashpos < pos) {
                 path     = "/";
