Skip to content

Commit c7c5803

Browse files
authored
Merge pull request #361 from evanchooly/ipv6
correct ipv6 address handling when building MongoClients
2 parents dcab53d + 2a9b676 commit c7c5803

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

driver-core/src/main/com/mongodb/ServerAddress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public ServerAddress(final String host, final int port) {
109109
}
110110
portToUse = Integer.parseInt(host.substring(portIdx + 2));
111111
}
112-
hostToUse = host.substring(1, idx);
112+
hostToUse = host.substring(0, idx + 1);
113113
} else {
114114
int idx = hostToUse.indexOf(":");
115115
if (idx > 0) {

driver-core/src/test/unit/com/mongodb/ServerAddressSpecification.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ class ServerAddressSpecification extends Specification {
2929

3030
where:
3131
address | host | port
32-
new ServerAddress() | ServerAddress.defaultHost() | ServerAddress.defaultPort()
32+
new ServerAddress() | ServerAddress.defaultHost() | ServerAddress.defaultPort()
3333
new ServerAddress('10.0.0.1:1000') | '10.0.0.1' | 1000
3434
new ServerAddress('10.0.0.1') | '10.0.0.1' | ServerAddress.defaultPort()
3535
new ServerAddress('10.0.0.1', 1000) | '10.0.0.1' | 1000
3636
new ServerAddress('somewhere') | 'somewhere' | ServerAddress.defaultPort()
3737
new ServerAddress('SOMEWHERE') | 'somewhere' | ServerAddress.defaultPort()
3838
new ServerAddress('somewhere:1000') | 'somewhere' | 1000
3939
new ServerAddress('somewhere', 1000) | 'somewhere' | 1000
40-
new ServerAddress('[2010:836b:4179::836b:4179]') | '2010:836b:4179::836b:4179' | ServerAddress.defaultPort()
41-
new ServerAddress('[2010:836B:4179::836B:4179]') | '2010:836b:4179::836b:4179' | ServerAddress.defaultPort()
42-
new ServerAddress('[2010:836B:4179::836B:4179]:1000') | '2010:836b:4179::836b:4179' | 1000
43-
new ServerAddress('[2010:836B:4179::836B:4179]', 1000) | '2010:836b:4179::836b:4179' | 1000
40+
new ServerAddress('[2010:836b:4179::836b:4179]') | '[2010:836b:4179::836b:4179]' | ServerAddress.defaultPort()
41+
new ServerAddress('[2010:836B:4179::836B:4179]') | '[2010:836b:4179::836b:4179]' | ServerAddress.defaultPort()
42+
new ServerAddress('[2010:836B:4179::836B:4179]:1000') | '[2010:836b:4179::836b:4179]' | 1000
43+
new ServerAddress('[2010:836B:4179::836B:4179]', 1000) | '[2010:836b:4179::836b:4179]' | 1000
4444
}
4545

4646
def 'ipv4 host with a port specified should throw when a port is also specified as an argument'() {

driver-core/src/test/unit/com/mongodb/connection/JMXConnectionPoolListenerSpecification.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class JMXConnectionPoolListenerSpecification extends Specification {
120120
ObjectName objectName = new ObjectName(beanName)
121121

122122
then:
123-
objectName.toString() == "org.mongodb.driver:type=ConnectionPool,clusterId=${serverId.clusterId.value},host=\"::1\",port=27017"
123+
objectName.toString() == "org.mongodb.driver:type=ConnectionPool,clusterId=${serverId.clusterId.value},host=\"[::1]\",port=27017"
124124
}
125125

126126
def 'should include the description in the object name if set'() {

0 commit comments

Comments
 (0)