Skip to content

Commit

Permalink
Fix symlink check
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed May 21, 2023
1 parent 3292cc9 commit 5ec7913
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ private File getSafeFileWithExtension(File dir, String filename, String extensio
return new File(dir, filename);
}

private static final java.util.regex.Pattern SAFE_FILENAME_REGEX = java.util.regex.Pattern.compile("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+\\.[A-Za-z0-9]+$");

private boolean checkFilename(String filename) {
return filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+\\.[A-Za-z0-9]+$");
return SAFE_FILENAME_REGEX.matcher(filename).matches();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
* A backend that scans the folder tree, then caches the result for a certain amount of time.
Expand Down Expand Up @@ -67,7 +66,7 @@ private List<Path> scanFolder(Path root) {

try (DirectoryStream<Path> stream = Files.newDirectoryStream(root)) {
for (Path path : stream) {
path = WorldEdit.getInstance().getSafeOpenFile(null, schematicRoot.toFile(), path.toString(), null).toPath();
path = WorldEdit.getInstance().getSafeOpenFile(null, schematicRoot.toFile(), schematicRoot.relativize(path).toString(), null).toPath();
if (Files.isDirectory(path)) {
pathList.addAll(scanFolder(path));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void triggerInitialEvents(Path root) throws IOException, FilenameExcepti
Path schematicRoot = WorldEdit.getInstance().getSchematicsManager().getRoot();
eventConsumer.accept(new DirectoryCreatedEvent(root));
for (Path path : Files.newDirectoryStream(root)) {
path = WorldEdit.getInstance().getSafeOpenFile(null, schematicRoot.toFile(), path.toString(), null).toPath();
path = WorldEdit.getInstance().getSafeOpenFile(null, schematicRoot.toFile(), schematicRoot.relativize(path).toString(), null).toPath();
if (Files.isDirectory(path)) {
triggerInitialEvents(path);
} else {
Expand Down Expand Up @@ -165,7 +165,7 @@ public void start(Consumer<DirEntryChangeEvent> eventConsumer) {
path = parentPath.resolve(path);

if (kind.equals(StandardWatchEventKinds.ENTRY_CREATE)) {
path = WorldEdit.getInstance().getSafeOpenFile(null, schematicRoot.toFile(), path.toString(), null).toPath();
path = WorldEdit.getInstance().getSafeOpenFile(null, schematicRoot.toFile(), schematicRoot.relativize(path).toString(), null).toPath();

if (Files.isDirectory(path)) { // new subfolder created, create watch for it
try {
Expand Down

0 comments on commit 5ec7913

Please sign in to comment.