images: fixed cards download of some promo cards like SLD (★ and † in url problem, related to #13808);

This commit is contained in:
Oleg Agafonov 2025-08-10 13:03:53 +04:00
parent 6dd4f33db2
commit 192d8f36dd
2 changed files with 11 additions and 6 deletions

View file

@ -10,10 +10,7 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.*;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
@ -93,7 +90,9 @@ public class XmageURLConnection {
initDefaultProxy(); initDefaultProxy();
try { 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 // proxy settings
if (this.proxy != null) { if (this.proxy != null) {
@ -107,7 +106,7 @@ public class XmageURLConnection {
this.connection.setReadTimeout(CONNECTION_READING_TIMEOUT_MS); this.connection.setReadTimeout(CONNECTION_READING_TIMEOUT_MS);
initDefaultHeaders(); initDefaultHeaders();
} catch (IOException e) { } catch (IOException | URISyntaxException e) {
this.connection = null; this.connection = null;
} }
} }

View file

@ -43,6 +43,12 @@ public class DownloaderTest {
Assert.assertTrue("must have text data (redirect to login page)", s.contains("Sign in to GitHub")); 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 @Test
public void test_DownloadFile_ByHttp() throws IOException { public void test_DownloadFile_ByHttp() throws IOException {
// use any public image here // use any public image here