java.lang.Object
org.htmlunit.util.FileUtils
File utility class for functions not covered by third-party libraries.
- Author:
- Ronald Brill
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringsanitizeFilename(String name) Makes the given name usable as the name of a file, the way the browsers do it for downloaded files.
-
Method Details
-
sanitizeFilename
Makes the given name usable as the name of a file, the way the browsers do it for downloaded files.- Characters that are not allowed in file names on at least one platform
(
\ / : * ? " < > |), the control characters (U+0000 - U+001F) and DEL (U+007F) are replaced by an underscore. Because the path separators are replaced, the result is always a plain file name; e.g.../../evil.txtbecomes_.._evil.txt, so the name can be resolved against a folder without leaving it. - Leading dots and white space (no hidden files) and trailing dots and white space are removed.
The name is not checked any further; e.g. names reserved by Windows (like
CONorNUL) and the maximum length of a file name are not taken into account.- Parameters:
name- the name to sanitize, can benull- Returns:
- the sanitized name or
nullif the name isnullor nothing is left
- Characters that are not allowed in file names on at least one platform
(
-