Skip to content

Commit

Permalink
Apply simple filtering of the query string passed through to real dat…
Browse files Browse the repository at this point in the history
…abase drivers

Refs #345
  • Loading branch information
rnorth committed Jun 4, 2017
1 parent 8d83997 commit 86eec03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static Iterable<Object[]> data() {
new Object[][]{
{"jdbc:tc:mysql:5.5.43://hostname/databasename", false, false, false},
{"jdbc:tc:mysql://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql", true, false, false},
{"jdbc:tc:mysql://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false},
{"jdbc:tc:mysql://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction&useUnicode=yes", true, false, false},
{"jdbc:tc:mysql://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false},
{"jdbc:tc:mysql://hostname/databasename", false, false, false},
{"jdbc:tc:postgresql://hostname/databasename", false, false, false},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public synchronized Connection connect(String url, final Properties info) throws
/*
Create a connection using the delegated driver. The container must be ready to accept connections.
*/
Connection connection = container.createConnection(queryString);
String filteredQueryString = getQueryStringWithoutTCParams(queryString);
Connection connection = container.createConnection(filteredQueryString);

/*
If this container has not been initialized, AND
Expand Down Expand Up @@ -175,6 +176,14 @@ private Map<String, String> getContainerParameters(String url) {
return results;
}

private String getQueryStringWithoutTCParams(String queryString) {
return TC_PARAM_MATCHING_PATTERN.matcher(queryString)
.replaceAll("")
.replaceAll("\\?&", "?")
.replaceAll("&&", "&")
.replaceAll("[?&]$", "");
}

/**
* Wrap the connection, setting up a callback to be called when the connection is closed.
* <p>
Expand Down

0 comments on commit 86eec03

Please sign in to comment.