Skip to content

Commit 62b0a8b

Browse files
committed
JAVA-2082: Canonicalize ServerAddress host by lowercasing it.
1 parent 8fbdc19 commit 62b0a8b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/main/com/mongodb/ServerAddress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public ServerAddress( String host , int port )
9898
}
9999
}
100100

101-
_host = host;
101+
_host = host.toLowerCase();
102102
_port = port;
103103
}
104104

src/test/com/mongodb/ServerAddressTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public void testDefault() throws UnknownHostException {
3333
assertEquals(ServerAddress.defaultPort(), subject.getPort());
3434
}
3535

36+
@Test
37+
public void testLowerCaseHostName() throws UnknownHostException {
38+
final String capitalizedHostName = "SOMEWHERE";
39+
ServerAddress subject = new ServerAddress(capitalizedHostName);
40+
41+
assertEquals(capitalizedHostName.toLowerCase(), subject.getHost());
42+
}
43+
3644
@Test
3745
public void testParseIPV4WithoutPort() throws UnknownHostException {
3846
ServerAddress subject = new ServerAddress("10.0.0.1");
@@ -69,23 +77,23 @@ public void testParseDnsNameWithoutPort() throws UnknownHostException {
6977
public void testParseIPV6WithoutPort() throws UnknownHostException {
7078
ServerAddress subject = new ServerAddress("[2010:836B:4179::836B:4179]");
7179

72-
assertEquals("2010:836B:4179::836B:4179", subject.getHost());
80+
assertEquals("2010:836b:4179::836b:4179", subject.getHost());
7381
assertEquals(ServerAddress.defaultPort(), subject.getPort());
7482
}
7583

7684
@Test
7785
public void testParseIPV6WithPort() throws UnknownHostException {
7886
ServerAddress subject = new ServerAddress("[2010:836B:4179::836B:4179]:1000");
7987

80-
assertEquals("2010:836B:4179::836B:4179", subject.getHost());
88+
assertEquals("2010:836b:4179::836b:4179", subject.getHost());
8189
assertEquals(1000, subject.getPort());
8290
}
8391

8492
@Test
8593
public void testIPV6WithPort() throws UnknownHostException {
8694
ServerAddress subject = new ServerAddress("[2010:836B:4179::836B:4179]", 1000);
8795

88-
assertEquals("2010:836B:4179::836B:4179", subject.getHost());
96+
assertEquals("2010:836b:4179::836b:4179", subject.getHost());
8997
assertEquals(1000, subject.getPort());
9098
}
9199

0 commit comments

Comments
 (0)