You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2020/04/28 15:05:43 UTC

[incubator-iotdb] 01/01: fix iotdb-531, jdbc url does not support domain issue

This is an automated email from the ASF dual-hosted git repository.

hxd pushed a commit to branch iotdb-531
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit 55d44dd7519d8998c553fb4a1686a0fabfd74b31
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Tue Apr 28 23:05:17 2020 +0800

    fix iotdb-531, jdbc url does not support domain issue
---
 .../src/main/java/org/apache/iotdb/jdbc/Utils.java | 34 ++++++++--------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
index 6e5e540..5d2878c 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
@@ -37,6 +37,8 @@ import org.apache.iotdb.tsfile.utils.BytesUtils;
  */
 public class Utils {
 
+  static final Pattern URL_PATTERN = Pattern.compile("([^:]+):([0-9]{1,5})/?");
+
   /**
    * Parse JDBC connection URL The only supported format of the URL is:
    * jdbc:iotdb://localhost:6667/.
@@ -48,31 +50,19 @@ public class Utils {
       return params;
     }
     boolean isUrlLegal = false;
-    Pattern pattern = Pattern.compile("^"
-        + "(((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}" // Domain name
-        + "|"
-        + "localhost" // localhost
-        + "|"
-        + "(([0-9]{1,3}\\.){3})[0-9]{1,3})" // Ip
-        + ":"
-        + "[0-9]{1,5}" // Port
-        + "/?$");
-    String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
-    Matcher matcher = pattern.matcher(subURL);
-    if(matcher.matches()) {
-      isUrlLegal = true;
-    }
-    String[] DomainAndPort;
-    if(subURL.contains("/")) {
-      DomainAndPort = subURL.substring(0, subURL.length()-1).split(":");
-    } else {
-      DomainAndPort = subURL.split(":");
+    Matcher matcher = null;
+    if (url.startsWith(Config.IOTDB_URL_PREFIX)) {
+      String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
+      matcher = URL_PATTERN.matcher(subURL);
+      if (matcher.matches()) {
+        isUrlLegal = true;
+      }
     }
-    params.setHost(DomainAndPort[0]);
-    params.setPort(Integer.parseInt(DomainAndPort[1]));
     if (!isUrlLegal) {
-      throw new IoTDBURLException("Error url format, url should be jdbc:iotdb://domain|ip:port/ or jdbc:iotdb://domain|ip:port");
+      throw new IoTDBURLException("Error url format, url should be jdbc:iotdb://anything:port/ or jdbc:iotdb://anything:port");
     }
+    params.setHost(matcher.group(1));
+    params.setPort(Integer.parseInt(matcher.group(2)));
 
     if (info.containsKey(Config.AUTH_USER)) {
       params.setUsername(info.getProperty(Config.AUTH_USER));