@Test public void validate_true() { assertTrue(FileNameValidator.validate("this_is_valid_file_name...")); assertTrue(FileNameValidator.validate("...this_is_valid_file_name...")); assertTrue(FileNameValidator.validate("this_is_valid_file_name...ä")); }
public static boolean validate(String filename) { if (filename == null) { return false; } Arrays.sort(FILE_NAME_FORBIDDEN_CHARS); Arrays.sort(FILE_NAME_ACCEPTED_CHARS); for (int i = 0; i < filename.length(); i++) { char character = filename.charAt(i); if (Arrays.binarySearch(FILE_NAME_ACCEPTED_CHARS, character) >= 0) { continue; } else if (character < 33 || character > 255 || Arrays.binarySearch(FILE_NAME_FORBIDDEN_CHARS, character) >= 0) { return false; } } if (StringUtils.remove(filename, "...").indexOf("..") > -1) { return false; } return true; }
FileNameValidator { public static boolean validate(String filename) { if (filename == null) { return false; } Arrays.sort(FILE_NAME_FORBIDDEN_CHARS); Arrays.sort(FILE_NAME_ACCEPTED_CHARS); for (int i = 0; i < filename.length(); i++) { char character = filename.charAt(i); if (Arrays.binarySearch(FILE_NAME_ACCEPTED_CHARS, character) >= 0) { continue; } else if (character < 33 || character > 255 || Arrays.binarySearch(FILE_NAME_FORBIDDEN_CHARS, character) >= 0) { return false; } } if (StringUtils.remove(filename, "...").indexOf("..") > -1) { return false; } return true; } }
FileNameValidator { public static boolean validate(String filename) { if (filename == null) { return false; } Arrays.sort(FILE_NAME_FORBIDDEN_CHARS); Arrays.sort(FILE_NAME_ACCEPTED_CHARS); for (int i = 0; i < filename.length(); i++) { char character = filename.charAt(i); if (Arrays.binarySearch(FILE_NAME_ACCEPTED_CHARS, character) >= 0) { continue; } else if (character < 33 || character > 255 || Arrays.binarySearch(FILE_NAME_FORBIDDEN_CHARS, character) >= 0) { return false; } } if (StringUtils.remove(filename, "...").indexOf("..") > -1) { return false; } return true; }  }
FileNameValidator { public static boolean validate(String filename) { if (filename == null) { return false; } Arrays.sort(FILE_NAME_FORBIDDEN_CHARS); Arrays.sort(FILE_NAME_ACCEPTED_CHARS); for (int i = 0; i < filename.length(); i++) { char character = filename.charAt(i); if (Arrays.binarySearch(FILE_NAME_ACCEPTED_CHARS, character) >= 0) { continue; } else if (character < 33 || character > 255 || Arrays.binarySearch(FILE_NAME_FORBIDDEN_CHARS, character) >= 0) { return false; } } if (StringUtils.remove(filename, "...").indexOf("..") > -1) { return false; } return true; }  static boolean validate(String filename); }
FileNameValidator { public static boolean validate(String filename) { if (filename == null) { return false; } Arrays.sort(FILE_NAME_FORBIDDEN_CHARS); Arrays.sort(FILE_NAME_ACCEPTED_CHARS); for (int i = 0; i < filename.length(); i++) { char character = filename.charAt(i); if (Arrays.binarySearch(FILE_NAME_ACCEPTED_CHARS, character) >= 0) { continue; } else if (character < 33 || character > 255 || Arrays.binarySearch(FILE_NAME_FORBIDDEN_CHARS, character) >= 0) { return false; } } if (StringUtils.remove(filename, "...").indexOf("..") > -1) { return false; } return true; }  static boolean validate(String filename);  }