From beca3a707d741825a0c838ff728dcca767ce38b2 Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 30 Aug 2020 12:11:34 -0400 Subject: [PATCH] Workaround for snapshot files with not-to-spec slashes. --- .../world/storage/TrueZipMcRegionChunkStore.java | 11 ++++++++--- .../world/storage/ZippedMcRegionChunkStore.java | 12 +++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/TrueZipMcRegionChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/TrueZipMcRegionChunkStore.java index 879410d75..679d7257c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/TrueZipMcRegionChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/TrueZipMcRegionChunkStore.java @@ -97,10 +97,15 @@ protected InputStream getInputStream(String name, String worldName) throws IOExc for (Enumeration e = zip.entries(); e.hasMoreElements(); ) { ZipEntry testEntry = e.nextElement(); // Check for world - if (worldPattern.matcher(testEntry.getName()).matches()) { + String entryName = testEntry.getName(); + if (worldPattern.matcher(entryName).matches()) { // Check for file - if (pattern.matcher(testEntry.getName()).matches()) { - folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf('/')); + if (pattern.matcher(entryName).matches()) { + int endIndex = entryName.lastIndexOf('/'); + if (endIndex < 0) { + endIndex = entryName.lastIndexOf('\\'); + } + folder = entryName.substring(0, endIndex); if (folder.endsWith("poi")) { continue; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ZippedMcRegionChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ZippedMcRegionChunkStore.java index 4b0272be0..030004ee3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ZippedMcRegionChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ZippedMcRegionChunkStore.java @@ -81,12 +81,18 @@ protected InputStream getInputStream(String name, String worldName) throws IOExc } } else { Pattern pattern = Pattern.compile(".*\\.mc[ra]$"); + Pattern worldPattern = Pattern.compile(worldName + "[\\\\/].*"); for (Enumeration e = zip.entries(); e.hasMoreElements(); ) { ZipEntry testEntry = e.nextElement(); // Check for world - if (testEntry.getName().startsWith(worldName + "/")) { - if (pattern.matcher(testEntry.getName()).matches()) { // does entry end in .mca - folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf('/')); + String entryName = testEntry.getName(); + if (worldPattern.matcher(entryName).matches()) { + if (pattern.matcher(entryName).matches()) { // does entry end in .mca + int endIndex = entryName.lastIndexOf('/'); + if (endIndex < 0) { + endIndex = entryName.lastIndexOf('\\'); + } + folder = entryName.substring(0, endIndex); if (folder.endsWith("poi")) { continue; }