Fix (and no longer be symlink safe again )-;)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.github.skippyall.ruler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
@@ -12,10 +13,12 @@ public class FileUtils {
|
||||
|
||||
public static String removeExtension(String path) {
|
||||
if(path.contains(".")) {
|
||||
return path.substring(0, path.lastIndexOf('.'));
|
||||
} else {
|
||||
return path;
|
||||
int index = path.lastIndexOf('.');
|
||||
if(index > path.lastIndexOf(FileSystems.getDefault().getSeparator())) {
|
||||
return path.substring(0, index);
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static String getExtension(Path path) {
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ConfigLoader {
|
||||
}
|
||||
RuleConfig config = null;
|
||||
Path configPath = FileUtils.append(fileWithoutExtension, ".config.json");
|
||||
String rulePath = RuleUtils.getRulePathFromWithoutExtension(fileWithoutExtension.toString());
|
||||
String rulePath = RuleUtils.getRulePath(fileWithoutExtension);
|
||||
if(Files.isRegularFile(configPath)) {
|
||||
try {
|
||||
config = RuleConfig.loadFromJson(JsonParser.parseReader(Files.newBufferedReader(configPath)), rulePath);
|
||||
|
||||
@@ -35,7 +35,8 @@ public class RuleUtils {
|
||||
}
|
||||
|
||||
public static boolean isValidRulePath(String path) {
|
||||
return path.matches("([A-Za-z0-9\\-_.]+)") &&
|
||||
return path.isEmpty() ||
|
||||
path.matches("([A-Za-z0-9\\-_.]+)") &&
|
||||
Arrays.stream(path.split("\\.")).noneMatch(String::isEmpty);
|
||||
}
|
||||
|
||||
@@ -46,11 +47,7 @@ public class RuleUtils {
|
||||
}
|
||||
|
||||
public static boolean isInDirectory(Path path) {
|
||||
try {
|
||||
return path.toRealPath().startsWith(getRoot());
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return path.toAbsolutePath().startsWith(getRoot());
|
||||
}
|
||||
|
||||
public static void checkDirectory(Path path) throws InvalidRulePathException {
|
||||
|
||||
Reference in New Issue
Block a user