Skip to content

Commit

Permalink
fix uri path issues
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed May 26, 2024
1 parent 6b96c1d commit 83c3399
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/com/cleanroommc/groovyscript/sandbox/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 83c3399

Please sign in to comment.