fix NumberFormat exception in MysqlURLParser (#36)

Delegate @ascrutae 's approval, his GitHub account has an issue for now.
This commit is contained in:
wuguanyu 2021-09-25 20:59:49 +08:00 committed by GitHub
parent c5657e83b3
commit 1b90f6892b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -21,6 +21,7 @@ Release Notes.
* Add benchmark result for `exception-ignore` plugin and polish plugin guide.
* Provide Alibaba Druid database connection pool plugin.
* Provide HikariCP database connection pool plugin.
* Fix NumberFormat exception in jdbc-commons plugin when MysqlURLParser parser jdbcurl
* Provide Alibaba Fastjson parser/generator plugin.
* Fix a tracing context leak of SpringMVC plugin, when an internal exception throws due to response can't be found.
* Make GRPC log reporter sharing GRPC channel with other reporters of agent. Remove config items of `agent.conf`, `plugin.toolkit.log.grpc.reporter.server_host`, `plugin.toolkit.log.grpc.reporter.server_port`, and `plugin.toolkit.log.grpc.reporter.upstream_timeout`.

View File

@ -45,8 +45,15 @@ public class MysqlURLParser extends AbstractURLParser {
protected URLLocation fetchDatabaseHostsIndexRange() {
int hostLabelStartIndex = url.indexOf("//");
int hostLabelEndIndex = url.indexOf("/", hostLabelStartIndex + 2);
int hostLabelEndIndexWithParameter = url.indexOf("?", hostLabelStartIndex + 2);
if (hostLabelEndIndex == -1) {
hostLabelEndIndex = url.indexOf("?", hostLabelStartIndex + 2);
hostLabelEndIndex = hostLabelEndIndexWithParameter;
}
if (hostLabelEndIndexWithParameter < hostLabelEndIndex && hostLabelEndIndexWithParameter != -1) {
hostLabelEndIndex = hostLabelEndIndexWithParameter;
}
if (hostLabelEndIndex == -1) {
hostLabelEndIndex = url.length();
}
return new URLLocation(hostLabelStartIndex + 2, hostLabelEndIndex);
}
@ -61,6 +68,10 @@ public class MysqlURLParser extends AbstractURLParser {
protected URLLocation fetchDatabaseNameIndexRange(int startSize) {
int databaseStartTag = url.indexOf("/", startSize);
int parameterStartTag = url.indexOf("?", startSize);
if (parameterStartTag < databaseStartTag && parameterStartTag != -1) {
return null;
}
if (databaseStartTag == -1) {
return null;
}

View File

@ -57,6 +57,14 @@ public class URLParserTest {
assertThat(connectionInfo.getDatabasePeer(), is("primaryhost:3307,secondaryhost1:3306,secondaryhost2:3306"));
}
@Test
public void testParseMysqlJDBCURLWitOutDatabase() {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost:3307?profileSQL=true");
assertThat(connectionInfo.getDBType(), is("Mysql"));
assertThat(connectionInfo.getDatabaseName(), is(""));
assertThat(connectionInfo.getDatabasePeer(), is("primaryhost:3307"));
}
@Test
public void testParseMysqlJDBCURLWithConnectorJs() {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql:replication://master,slave1,slave2,slave3/test");