changeset 790:547eca89fc5e monetdbs

Adjustments after applying changes to libmapi
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 30 Nov 2023 14:21:46 +0100 (16 months ago)
parents 88c5b678e974
children 4de810c22328
files src/main/java/org/monetdb/mcl/net/MonetUrlParser.java src/main/java/org/monetdb/mcl/net/Target.java tests/tests.md
diffstat 3 files changed, 56 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/monetdb/mcl/net/MonetUrlParser.java
+++ b/src/main/java/org/monetdb/mcl/net/MonetUrlParser.java
@@ -16,6 +16,16 @@ public class MonetUrlParser {
     public MonetUrlParser(Properties props, String url) throws URISyntaxException {
         this.props = props;
         this.urlText = url;
+        // we want to accept monetdb:// but the Java URI parser rejects that.
+        switch (url) {
+            case "monetdb:-":
+            case "monetdbs:-":
+                throw new URISyntaxException(url, "invalid MonetDB URL");
+            case "monetdb://":
+            case "monetdbs://":
+                url += "-";
+                break;
+        }
         this.url = new URI(url);
     }
 
@@ -124,31 +134,27 @@ public class MonetUrlParser {
             }
             host = "";
             remainder = "";
-        } else if (authority.startsWith("[")) {
-            // IPv6
-            pos = authority.indexOf(']');
-            if (pos < 0)
-                throw new URISyntaxException(urlText, "unmatched '['");
-            host = authority.substring(1, pos);
-            remainder = authority.substring(pos + 1);
-        } else if ((pos = authority.indexOf(':')) >= 0){
-            host = authority.substring(0, pos);
-            remainder = authority.substring(pos);
-        } else {
-            host = authority;
+        } else if (authority.equals("-")) {
+            host = "";
             remainder = "";
+        } else {
+            if (authority.startsWith("[")) {
+                // IPv6
+                pos = authority.indexOf(']');
+                if (pos < 0)
+                    throw new URISyntaxException(urlText, "unmatched '['");
+                host = authority.substring(1, pos);
+                remainder = authority.substring(pos + 1);
+            } else if ((pos = authority.indexOf(':')) >= 0) {
+                host = authority.substring(0, pos);
+                remainder = authority.substring(pos);
+            } else {
+                host = authority;
+                remainder = "";
+            }
         }
-        switch (host) {
-            case "localhost":
-                set(Parameter.HOST, "");
-                break;
-            case "localhost.":
-                set(Parameter.HOST, "localhost");
-                break;
-            default:
-                set(Parameter.HOST, host);
-                break;
-        }
+        host = unwrapLocalhost(host);
+        set(Parameter.HOST, host);
 
         if (remainder.isEmpty()) {
             // do nothing
@@ -206,6 +212,30 @@ public class MonetUrlParser {
         }
     }
 
+    public static String wrapLocalhost(String host) {
+        switch (host) {
+            case "localhost":
+                host = "localhost.";
+                break;
+            case "":
+                host = "localhost";
+                break;
+        }
+        return host;
+    }
+
+    public static String unwrapLocalhost(String host) {
+        switch (host) {
+            case "localhost":
+                host = "";
+                break;
+            case "localhost.":
+                host = "localhost";
+                break;
+        }
+        return host;
+    }
+
 
     private void parseClassic() throws URISyntaxException {
         String scheme = url.getScheme();
--- a/src/main/java/org/monetdb/mcl/net/Target.java
+++ b/src/main/java/org/monetdb/mcl/net/Target.java
@@ -5,7 +5,7 @@ import java.util.Properties;
 import java.util.regex.Pattern;
 
 public class Target {
-    private static Pattern namePattern = Pattern.compile("^[a-zA-Z_][-a-zA-Z0-9_.]*$");
+    private static Pattern namePattern = Pattern.compile("^[a-zzA-Z_][-a-zA-Z0-9_.]*$");
     private static Pattern hashPattern = Pattern.compile("^sha256:[0-9a-fA-F:]*$");
     private final boolean tls;
     private final String host;
--- a/tests/tests.md
+++ b/tests/tests.md
@@ -672,8 +672,8 @@ REJECT monetdb:
 REJECT monetdbs:
 REJECT monetdb:/
 REJECT monetdbs:/
-REJECT monetdb://
-REJECT monetdbs://
+ACCEPT monetdb://
+ACCEPT monetdbs://
 ACCEPT monetdb:///
 ACCEPT monetdbs:///
 ```