From 83c3399632caf42d9b6b979acb21092bf24a1106 Mon Sep 17 00:00:00 2001 From: brachy84 Date: Sun, 26 May 2024 14:12:08 +0200 Subject: [PATCH] fix uri path issues --- .../groovyscript/sandbox/FileUtil.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/sandbox/FileUtil.java b/src/main/java/com/cleanroommc/groovyscript/sandbox/FileUtil.java index a52b4321e..c1b39c494 100644 --- a/src/main/java/com/cleanroommc/groovyscript/sandbox/FileUtil.java +++ b/src/main/java/com/cleanroommc/groovyscript/sandbox/FileUtil.java @@ -5,23 +5,24 @@ import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.nio.file.Files; public class FileUtil { public static String relativize(String rootPath, String longerThanRootPath) { + try { + longerThanRootPath = URLDecoder.decode(longerThanRootPath, "UTF-8"); + } catch (UnsupportedEncodingException ignored) { + } + if (File.separatorChar != '/') { longerThanRootPath = longerThanRootPath.replace('/', File.separatorChar); } int index = longerThanRootPath.indexOf(rootPath); if (index < 0) { - if (longerThanRootPath.contains("%20")) { - longerThanRootPath = longerThanRootPath.replace("%20", " "); - index = longerThanRootPath.indexOf(rootPath); - } - if (index < 0) { - throw new IllegalArgumentException("The path '" + longerThanRootPath + "' does not contain the root path '" + rootPath + "'"); - } + throw new IllegalArgumentException("The path '" + longerThanRootPath + "' does not contain the root path '" + rootPath + "'"); } return longerThanRootPath.substring(index + rootPath.length() + 1); }