You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2025/08/12 01:57:03 UTC

(shardingsphere) branch master updated: Fix the bug that `StandardJdbcUrlParser` cannot parse the jdbcUrl of `ContainerDatabaseDriver` (#36259)

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

menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new a4588fcb868 Fix the bug that `StandardJdbcUrlParser` cannot parse the jdbcUrl of `ContainerDatabaseDriver` (#36259)
a4588fcb868 is described below

commit a4588fcb86805efe88dffad12acf7622d6171886
Author: Ling Hengqian <li...@outlook.com>
AuthorDate: Tue Aug 12 09:56:57 2025 +0800

    Fix the bug that `StandardJdbcUrlParser` cannot parse the jdbcUrl of `ContainerDatabaseDriver` (#36259)
---
 .../core/connector/url/StandardJdbcUrlParser.java    |  3 +++
 .../connector/url/StandardJdbcUrlParserTest.java     | 20 ++++++++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/connector/url/StandardJdbcUrlParser.java b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/connector/url/StandardJdbcUrlParser.java
index 2a4b20b05c9..39900c93d27 100644
--- a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/connector/url/StandardJdbcUrlParser.java
+++ b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/connector/url/StandardJdbcUrlParser.java
@@ -69,6 +69,9 @@ public final class StandardJdbcUrlParser {
         ShardingSpherePreconditions.checkState(matcher.matches(), () -> new UnrecognizedDatabaseURLException(jdbcUrl, CONNECTION_URL_PATTERN.pattern().replaceAll("%", "%%")));
         String authority = matcher.group(AUTHORITY_GROUP_KEY);
         ShardingSpherePreconditions.checkNotNull(authority, () -> new UnrecognizedDatabaseURLException(jdbcUrl, CONNECTION_URL_PATTERN.pattern().replaceAll("%", "%%")));
+        if (authority.isEmpty()) {
+            return new JdbcUrl("", -1, matcher.group(PATH_GROUP_KEY), parseQueryProperties(matcher.group(QUERY_GROUP_KEY)));
+        }
         Matcher hostMatcher = HOST_PORT_PATTERN_PATTERN.matcher(authority);
         ShardingSpherePreconditions.checkState(hostMatcher.find(), () -> new UnrecognizedDatabaseURLException(jdbcUrl, CONNECTION_URL_PATTERN.pattern().replaceAll("%", "%%")));
         return new JdbcUrl(parseHostname(hostMatcher), parsePort(hostMatcher), matcher.group(PATH_GROUP_KEY), parseQueryProperties(matcher.group(QUERY_GROUP_KEY)));
diff --git a/infra/database/core/src/test/java/org/apache/shardingsphere/infra/database/core/connector/url/StandardJdbcUrlParserTest.java b/infra/database/core/src/test/java/org/apache/shardingsphere/infra/database/core/connector/url/StandardJdbcUrlParserTest.java
index bd236707027..de21a69c9c3 100644
--- a/infra/database/core/src/test/java/org/apache/shardingsphere/infra/database/core/connector/url/StandardJdbcUrlParserTest.java
+++ b/infra/database/core/src/test/java/org/apache/shardingsphere/infra/database/core/connector/url/StandardJdbcUrlParserTest.java
@@ -64,8 +64,24 @@ class StandardJdbcUrlParserTest {
                     Arguments.arguments("MySQL_with_replication", "jdbc:mysql:replication://master-ip:3306,slave-1-ip:3306,slave-2-ip:3306/foo_ds?useUnicode=true", "master-ip", 3306, "foo_ds",
                             PropertiesBuilder.build(new Property("useUnicode", Boolean.TRUE.toString()))),
                     Arguments.arguments("PostgreSQL_v4", "jdbc:postgresql://127.0.0.1:5432/foo_ds?prepareThreshold=1&preferQueryMode=extendedForPrepared", "127.0.0.1", 5432, "foo_ds",
-                            PropertiesBuilder.build(new Property("prepareThreshold", "1"), new Property("preferQueryMode", "extendedForPrepared"))));
-            
+                            PropertiesBuilder.build(new Property("prepareThreshold", "1"), new Property("preferQueryMode", "extendedForPrepared"))),
+                    Arguments.arguments("testcontainers_MySQL", "jdbc:tc:mysql:5.7.34:///demo_ds", "", -1, "demo_ds", new Properties()),
+                    Arguments.arguments("testcontainers_Postgres", "jdbc:tc:postgresql:9.6.8:///demo_ds", "", -1, "demo_ds", new Properties()),
+                    Arguments.arguments("testcontainers_PostGIS", "jdbc:tc:postgis:9.6-2.5:///demo_ds", "", -1, "demo_ds", new Properties()),
+                    Arguments.arguments("testcontainers_TimescaleDB", "jdbc:tc:timescaledb:2.1.0-pg13:///demo_ds", "", -1, "demo_ds", new Properties()),
+                    Arguments.arguments("testcontainers_Trino", "jdbc:tc:trino:352://localhost/memory/default", "localhost", -1, "memory/default", new Properties()),
+                    Arguments.arguments("testcontainers_CockroachDB", "jdbc:tc:cockroach:v21.2.3:///demo_ds", "", -1, "demo_ds", new Properties()),
+                    Arguments.arguments("testcontainers_TiDB", "jdbc:tc:tidb:v6.1.0:///demo_ds", "", -1, "demo_ds", new Properties()),
+                    Arguments.arguments("testcontainers_INITSCRIPT_CLASSPATH", "jdbc:tc:mysql:5.7.34:///demo_ds?TC_INITSCRIPT=somepath/init_mysql.sql", "", -1, "demo_ds",
+                            PropertiesBuilder.build(new Property("TC_INITSCRIPT", "somepath/init_mysql.sql"))),
+                    Arguments.arguments("testcontainers_INITSCRIPT", "jdbc:tc:mysql:5.7.34:///demo_ds?TC_INITSCRIPT=file:src/main/resources/init_mysql.sql", "", -1, "demo_ds",
+                            PropertiesBuilder.build(new Property("TC_INITSCRIPT", "file:src/main/resources/init_mysql.sql"))),
+                    Arguments.arguments("testcontainers_INITFUNCTION", "jdbc:tc:mysql:5.7.34:///demo_ds?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", "", -1, "demo_ds",
+                            PropertiesBuilder.build(new Property("TC_INITFUNCTION", "org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction"))),
+                    Arguments.arguments("testcontainers_DAEMON", "jdbc:tc:mysql:5.7.34:///demo_ds?TC_DAEMON=true", "", -1, "demo_ds",
+                            PropertiesBuilder.build(new Property("TC_DAEMON", Boolean.TRUE.toString()))),
+                    Arguments.arguments("testcontainers_TMPFS", "jdbc:tc:postgresql:9.6.8:///demo_ds?TC_TMPFS=/testtmpfs:rw", "", -1, "demo_ds",
+                            PropertiesBuilder.build(new Property("TC_TMPFS", "/testtmpfs:rw"))));
         }
     }
 }