From e04633d916692b3560c900a6855f7c3b76f6e4e6 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 10 Mar 2019 13:55:02 +0200 Subject: [PATCH] Improved name encoding of export filenames --- .../java/com/djrapitops/plan/system/export/JSONExport.java | 5 +++-- .../com/djrapitops/plan/system/export/SpecificExport.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/export/JSONExport.java b/Plan/common/src/main/java/com/djrapitops/plan/system/export/JSONExport.java index 4f92cec13..805512eac 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/export/JSONExport.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/export/JSONExport.java @@ -32,6 +32,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import java.io.File; import java.io.IOException; +import java.net.URLEncoder; import java.util.Collections; import java.util.UUID; @@ -77,7 +78,7 @@ public class JSONExport extends SpecificExport { try { File htmlLocation = getPlayerFolder(); htmlLocation.mkdirs(); - File exportFile = new File(htmlLocation, playerName.replace(" ", "%20").replace(".", "%2E") + ".json"); + File exportFile = new File(htmlLocation, URLEncoder.encode(playerName, "UTF-8") + ".json"); export(exportFile, Collections.singletonList(json)); } catch (IOException e) { @@ -94,7 +95,7 @@ public class JSONExport extends SpecificExport { try { File htmlLocation = getServerFolder(); htmlLocation.mkdirs(); - File exportFile = new File(htmlLocation, serverName.replace(" ", "%20").replace(".", "%2E") + ".json"); + File exportFile = new File(htmlLocation, URLEncoder.encode(serverName, "UTF-8") + ".json"); export(exportFile, Collections.singletonList(json)); } catch (IOException e) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/export/SpecificExport.java b/Plan/common/src/main/java/com/djrapitops/plan/system/export/SpecificExport.java index 653a97906..a84da8e30 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/export/SpecificExport.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/export/SpecificExport.java @@ -25,6 +25,7 @@ import com.djrapitops.plugin.api.Check; import java.io.File; import java.io.IOException; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; @@ -92,7 +93,7 @@ public abstract class SpecificExport { protected void exportPlayerPage(String playerName, String html) throws IOException { List lines = Arrays.asList(html.split("\n")); - File htmlLocation = new File(getPlayerFolder(), playerName.replace(" ", "%20").replace(".", "%2E")); + File htmlLocation = new File(getPlayerFolder(), URLEncoder.encode(playerName, "UTF-8").replace(".", "%2E")); htmlLocation.mkdirs(); File exportFile = new File(htmlLocation, "index.html"); @@ -127,7 +128,7 @@ public abstract class SpecificExport { if (serverUUID.equals(serverInfo.getServerUUID())) { htmlLocation = new File(getFolder(), "network"); } else { - htmlLocation = new File(getServerFolder(), serverName.replace(" ", "%20").replace(".", "%2E")); + htmlLocation = new File(getServerFolder(), URLEncoder.encode(serverName, "UTF-8").replace(".", "%2E")); html = html.replace("../", "../../"); } } else {