From 50e5137f52462da90466c5a3c797c24b970dabcf Mon Sep 17 00:00:00 2001 From: anthonyraymond Date: Mon, 17 Jul 2017 23:12:24 +0200 Subject: [PATCH] ipv6 placeholder is replaced by url encoded value --- .../araymond/joal/core/client/emulated/BitTorrentClient.java | 2 +- .../core/client/emulated/BitTorrentClientUrlBuilderTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/araymond/joal/core/client/emulated/BitTorrentClient.java b/src/main/java/org/araymond/joal/core/client/emulated/BitTorrentClient.java index d99186f..5cf1c32 100644 --- a/src/main/java/org/araymond/joal/core/client/emulated/BitTorrentClient.java +++ b/src/main/java/org/araymond/joal/core/client/emulated/BitTorrentClient.java @@ -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}", ""); diff --git a/src/test/java/org/araymond/joal/core/client/emulated/BitTorrentClientUrlBuilderTest.java b/src/test/java/org/araymond/joal/core/client/emulated/BitTorrentClientUrlBuilderTest.java index a96a0e0..df95725 100644 --- a/src/test/java/org/araymond/joal/core/client/emulated/BitTorrentClientUrlBuilderTest.java +++ b/src/test/java/org/araymond/joal/core/client/emulated/BitTorrentClientUrlBuilderTest.java @@ -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