Skip to content

Commit

Permalink
fix: host less URI ignores the database name
Browse files Browse the repository at this point in the history
  • Loading branch information
wai4y committed Jan 31, 2024
1 parent 78d1768 commit 7d55058
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void parseUrl() {
//In case it matches to the default pattern
Matcher dbInstanceMatcher = Patterns.DB_INSTANCE_MATCHING_PATTERN.matcher(dbHostString);
if (dbInstanceMatcher.matches()) {
databaseHost = Optional.of(dbInstanceMatcher.group("databaseHost"));
databaseHost = Optional.ofNullable(dbInstanceMatcher.group("databaseHost"));
databasePort = Optional.ofNullable(dbInstanceMatcher.group("databasePort")).map(Integer::valueOf);
databaseName = Optional.of(dbInstanceMatcher.group("databaseName"));
}
Expand Down Expand Up @@ -227,13 +227,13 @@ public interface Patterns {

//Matches to part of string - hostname:port/databasename
Pattern DB_INSTANCE_MATCHING_PATTERN = Pattern.compile(
"(?<databaseHost>[^:]+)" +
"((?<databaseHost>[^:]+)" +
"(:(?<databasePort>[0-9]+))?" +
"(" +
"(?<sidOrServiceName>[:/])" +
"|" +
";databaseName=" +
")" +
")|/)" +
"(?<databaseName>[^\\\\?]+)"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ public void testDaemonCapture() {

assertThat(url.isInDaemonMode()).as("Daemon flag is set to true.").isTrue();
}

@Test
public void testHostLessUrl() {
String urlString = "jdbc:tc:mysql:///dbname";
ConnectionUrl url = ConnectionUrl.newInstance(urlString);

assertThat(url.getDatabaseName()).as("Database Name value is expected").contains("dbname");
}
}

0 comments on commit 7d55058

Please sign in to comment.