package net.wizardsoflua.filesystem;

import static com.google.common.base.Preconditions.checkNotNull;

import java.io.File;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.util.List;

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;

public class RestrictedFileSystem extends DelegatingFileSystem {
  private Path topmostDirectory;

  public RestrictedFileSystem(FileSystem delegate, Path topmostDirectory) {
    super(delegate);
    this.topmostDirectory = checkNotNull(topmostDirectory, "topmostDirectory==null!");
  }

  @Override
  public Path getPath(String first, String... more) {
    List<String> parts = Lists.asList(first, more);
    String filename = Joiner.on(File.separatorChar).join(parts);
    Path result = PathUtil.toPath(topmostDirectory, filename);
    return result;
  }
}

@@ -631,24 +631,97 @@
 ... more) %7B%0A
+    if (first.startsWith(%22/%22)) %7B%0A      first = first.substring(1);%0A    %7D%0A
     List%3CStr

allow path values to start with a /