@Test public void testToFullPath_ValidationFailure() { final String oneLevelUp = File.separator + ".." + File.separator; assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> toFullPath("/tmp/jarviz/jars", oneLevelUp + "fooBar123.jar")); }
public static String toFullPath(@Nonnull final String dirPath, @Nonnull final String fileName) { final String dirPathWithSeparator = dirPath.endsWith(File.separator) ? dirPath : dirPath + File.separator; final String fullFileName = dirPathWithSeparator + fileName; if (!getCanonicalName(fullFileName).startsWith(getCanonicalName(dirPathWithSeparator))) { throw new IllegalArgumentException("Invalid file name: " + fileName); } return fullFileName; }
FileReadWriteUtils { public static String toFullPath(@Nonnull final String dirPath, @Nonnull final String fileName) { final String dirPathWithSeparator = dirPath.endsWith(File.separator) ? dirPath : dirPath + File.separator; final String fullFileName = dirPathWithSeparator + fileName; if (!getCanonicalName(fullFileName).startsWith(getCanonicalName(dirPathWithSeparator))) { throw new IllegalArgumentException("Invalid file name: " + fileName); } return fullFileName; } }
FileReadWriteUtils { public static String toFullPath(@Nonnull final String dirPath, @Nonnull final String fileName) { final String dirPathWithSeparator = dirPath.endsWith(File.separator) ? dirPath : dirPath + File.separator; final String fullFileName = dirPathWithSeparator + fileName; if (!getCanonicalName(fullFileName).startsWith(getCanonicalName(dirPathWithSeparator))) { throw new IllegalArgumentException("Invalid file name: " + fileName); } return fullFileName; } private  FileReadWriteUtils(); }
FileReadWriteUtils { public static String toFullPath(@Nonnull final String dirPath, @Nonnull final String fileName) { final String dirPathWithSeparator = dirPath.endsWith(File.separator) ? dirPath : dirPath + File.separator; final String fullFileName = dirPathWithSeparator + fileName; if (!getCanonicalName(fullFileName).startsWith(getCanonicalName(dirPathWithSeparator))) { throw new IllegalArgumentException("Invalid file name: " + fileName); } return fullFileName; } private  FileReadWriteUtils(); static File getOrCreateDirectory(@Nonnull final String path); static String readResourceAsString(@Nonnull final String resourceFileName); static String readFileAsString(@Nonnull final File file); static String toFullPath(@Nonnull final String dirPath, @Nonnull final String fileName); static void writeToFile(final String fileName, final Consumer<Writer> writeHandler); }
FileReadWriteUtils { public static String toFullPath(@Nonnull final String dirPath, @Nonnull final String fileName) { final String dirPathWithSeparator = dirPath.endsWith(File.separator) ? dirPath : dirPath + File.separator; final String fullFileName = dirPathWithSeparator + fileName; if (!getCanonicalName(fullFileName).startsWith(getCanonicalName(dirPathWithSeparator))) { throw new IllegalArgumentException("Invalid file name: " + fileName); } return fullFileName; } private  FileReadWriteUtils(); static File getOrCreateDirectory(@Nonnull final String path); static String readResourceAsString(@Nonnull final String resourceFileName); static String readFileAsString(@Nonnull final File file); static String toFullPath(@Nonnull final String dirPath, @Nonnull final String fileName); static void writeToFile(final String fileName, final Consumer<Writer> writeHandler);  }