ipv6 placeholder is replaced by url encoded value

This commit is contained in:
anthonyraymond 2017-07-17 23:12:24 +02:00
parent dfebbd9504
commit 50e5137f52
2 changed files with 2 additions and 2 deletions

View file

@ -74,7 +74,7 @@ public class BitTorrentClient {
if (connectionHandler.getIpAddress() instanceof Inet4Address) {
emulatedClientQuery = emulatedClientQuery.replaceAll("\\{ip}", connectionHandler.getIpAddress().getHostAddress());
} else if(connectionHandler.getIpAddress() instanceof Inet6Address) {
emulatedClientQuery = emulatedClientQuery.replaceAll("\\{ipv6}", connectionHandler.getIpAddress().getHostAddress());
emulatedClientQuery = emulatedClientQuery.replaceAll("\\{ipv6}", URLEncoder.encode(connectionHandler.getIpAddress().getHostAddress(), Torrent.BYTE_ENCODING));
}
emulatedClientQuery = emulatedClientQuery.replaceAll("[&]*[a-zA-Z0-9]+=\\{ipv6}", "");
emulatedClientQuery = emulatedClientQuery.replaceAll("[&]*[a-zA-Z0-9]+=\\{ip}", "");

View file

@ -176,7 +176,7 @@ public class BitTorrentClientUrlBuilderTest {
final URL announceURL = client.buildAnnounceURL(new URL("http://my.tracker.com/announce"), RequestEvent.STARTED, torrent, connHandler);
assertThat(announceURL.getQuery())
.isEqualTo("ipv6=" + connHandler.getIpAddress().getHostAddress());
.isEqualTo("ipv6=" + URLEncoder.encode(connHandler.getIpAddress().getHostAddress(), Torrent.BYTE_ENCODING));
}
@Test