Utility API to check if a file is physically inside a given directory

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      Commonly need to verify that file paths provided by a user are really relative and do not refer to locations outside a workspace or the like. Should have something in Util along the lines of

      public static boolean isInside(File root, File f) throws IOException {
          String path = f.getCanonicalPath();
          String rootPath = root.getCanonicalPath();
          return path.equals(rootPath) || path.startsWith(rootPath + File.separatorChar);
      }
      

      and a matching method in FilePath.

            Assignee:
            Unassigned
            Reporter:
            Jesse Glick
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: