From 192d8f36ddb90361dd920a4d27c77645857229c6 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sun, 10 Aug 2025 13:03:53 +0400 Subject: [PATCH] =?UTF-8?q?images:=20fixed=20cards=20download=20of=20some?= =?UTF-8?q?=20promo=20cards=20like=20SLD=20(=E2=98=85=20and=20=E2=80=A0=20?= =?UTF-8?q?in=20url=20problem,=20related=20to=20#13808);?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/mage/client/remote/XmageURLConnection.java | 11 +++++------ .../test/java/mage/client/util/DownloaderTest.java | 6 ++++++ 2 files changed, 11 insertions(+), 6 deletions(-) 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