You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2020/04/30 03:25:26 UTC

[incubator-iotdb] branch rel/0.9 updated: [IOTDB-531] fix that JDBC URL does not support domain issue (#1118)

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

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


The following commit(s) were added to refs/heads/rel/0.9 by this push:
     new b064e90  [IOTDB-531] fix that JDBC URL does not support domain issue (#1118)
b064e90 is described below

commit b064e90ef99216ff7548070409ef09b461cef406
Author: Xiangdong Huang <hx...@qq.com>
AuthorDate: Thu Apr 30 11:25:17 2020 +0800

    [IOTDB-531] fix that JDBC URL does not support domain issue (#1118)
    
    * fix iotdb-531, jdbc url does not support domain issue
---
 .../src/main/java/org/apache/iotdb/jdbc/Utils.java | 34 ++++++++--------------
 .../test/java/org/apache/iotdb/jdbc/UtilsTest.java |  4 +--
 2 files changed, 14 insertions(+), 24 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));
diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java
index c46cf4a..31e4b14 100644
--- a/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java
+++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java
@@ -99,7 +99,7 @@ public class UtilsTest {
     assertEquals(params.getPort(), port);
   }
 
-  @Test(expected = NumberFormatException.class)
+  @Test(expected = IoTDBURLException.class)
   public void testParseWrongDomain() throws IoTDBURLException {
     String userName = "test";
     String userPwd = "test";
@@ -113,7 +113,7 @@ public class UtilsTest {
             properties);
   }
 
-  @Test(expected = IoTDBURLException.class)
+  @Test
   public void testParseWrongIP() throws IoTDBURLException {
     String userName = "test";
     String userPwd = "test";