diff --git a/Mage.Client/src/main/java/mage/client/remote/XmageURLConnection.java b/Mage.Client/src/main/java/mage/client/remote/XmageURLConnection.java index ef4e38fba03..6b2ebad8a66 100644 --- a/Mage.Client/src/main/java/mage/client/remote/XmageURLConnection.java +++ b/Mage.Client/src/main/java/mage/client/remote/XmageURLConnection.java @@ -10,10 +10,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.URL; +import java.net.*; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; @@ -93,7 +90,9 @@ public class XmageURLConnection { initDefaultProxy(); try { - URL url = new URL(this.url); + // convert utf8 url to ascii format (e.g. url encode) + URI uri = new URI(this.url); + URL url = new URL(uri.toASCIIString()); // proxy settings if (this.proxy != null) { @@ -107,7 +106,7 @@ public class XmageURLConnection { this.connection.setReadTimeout(CONNECTION_READING_TIMEOUT_MS); initDefaultHeaders(); - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { this.connection = null; } } diff --git a/Mage.Client/src/test/java/mage/client/util/DownloaderTest.java b/Mage.Client/src/test/java/mage/client/util/DownloaderTest.java index f90f7e8df0a..d81812d92b8 100644 --- a/Mage.Client/src/test/java/mage/client/util/DownloaderTest.java +++ b/Mage.Client/src/test/java/mage/client/util/DownloaderTest.java @@ -43,6 +43,12 @@ public class DownloaderTest { Assert.assertTrue("must have text data (redirect to login page)", s.contains("Sign in to GitHub")); } + @Test + public void test_DownloadText_ScryfallUtf8() { + String s = XmageURLConnection.downloadText("https://api.scryfall.com/cards/sld/379★/en"); + Assert.assertTrue("must have text data (utf8 url must work)", s.contains("Zndrsplt, Eye of Wisdom")); + } + @Test public void test_DownloadFile_ByHttp() throws IOException { // use any public image here