Skip to content

Commit

Permalink
Fix filename sanitization in ClientCacheManager (#2339)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb0124 authored Nov 14, 2024
1 parent 8001233 commit 197a03b
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ public class ClientCacheManager {
private static final Reference2ObjectMap<IClientCache, ClientCacheInfo> caches = new Reference2ObjectArrayMap<>();
private static boolean shouldInit = true;

private static String sanitizeFilename(String input) {
return input.replaceAll("(?U)[^\\w-]+", "_").trim();
}

public static void init(String worldId) {
if (shouldInit) {
final Player player = Minecraft.getInstance().player;
worldFolder = new File(clientCacheDir, player.getName().getString() + "_" + player.getUUID() +
File.separator + worldId);
worldFolder = new File(clientCacheDir,
sanitizeFilename(player.getName().getString()) + "_" + player.getUUID() +
File.separator + sanitizeFilename(worldId));
worldFolder.mkdirs();
// to ensure any cache data that might somehow be lying around gets dealt with
clearCaches();
Expand Down

0 comments on commit 197a03b

Please sign in to comment.