Skip to content

Commit

Permalink
- renamed unix-specific format with prefix UNIX_
Browse files Browse the repository at this point in the history
 - renamed windows-specific format with prefix WINDOWS_ ; also removed _WINDOWS suffix
  - removed test on illegal chars for unix, since eg touch "?" or touch "<" are fine under linux (and result in the file being listed with ls ).

  see phax#74
  • Loading branch information
glelouet committed Jan 20, 2020
1 parent 6da54af commit 390c40a
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/main/java/com/helger/jcodemodel/util/JCFilenameHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public final class JCFilenameHelper
public static final char ILLEGAL_FILENAME_CHAR_REPLACEMENT = '_';

/** Special name of the current path */
public static final String PATH_CURRENT = ".";
public static final String UNIX_PATH_CURRENT = ".";

/** Special name of the parent path */
public static final String PATH_PARENT = "..";
public static final String UNIX_PATH_PARENT = "..";

/** The Unix path separator character. */
public static final char UNIX_SEPARATOR = '/';
Expand Down Expand Up @@ -102,15 +102,14 @@ public final class JCFilenameHelper
* Illegal characters in Windows file names.<br>
* see http://en.wikipedia.org/wiki/Filename
*/
private static final char [] ILLEGAL_CHARACTERS_WINDOWS = { 0, '<', '>', '?', '*', ':', '|', '"' };
private static final char [] ILLEGAL_CHARACTERS_OTHERS = { 0, '<', '>', '?', '*', '|', '"' };
private static final char [] WINDOWS_ILLEGAL_CHARACTERS = { 0, '<', '>', '?', '*', ':', '|', '"' };

/**
* see http://www.w3.org/TR/widgets/#zip-relative <br>
* see http://forum.java.sun.com/thread.jspa?threadID=544334&tstart=165<br>
* see http://en.wikipedia.org/wiki/Filename
*/
private static final String [] ILLEGAL_PREFIXES = { "CLOCK$",
private static final String [] WINDOWS_ILLEGAL_PREFIXES = { "CLOCK$",
"CON",
"PRN",
"AUX",
Expand All @@ -133,7 +132,7 @@ public final class JCFilenameHelper
"LPT8",
"LPT9" };

private static final char [] ILLEGAL_SUFFIXES = new char [] { '.', ' ', '\t' };
private static final char [] WINDOWS_ILLEGAL_SUFFIXES = new char [] { '.', ' ', '\t' };

static
{
Expand Down Expand Up @@ -226,14 +225,9 @@ public static boolean isValidLinuxFilename (@Nullable final String sFilename)
return false;

// Check for reserved directories
if (PATH_CURRENT.equals (sFilename) || PATH_PARENT.equals (sFilename))
if (UNIX_PATH_CURRENT.equals (sFilename) || UNIX_PATH_PARENT.equals (sFilename))
return false;

// Check if file name contains any of the illegal characters
for (final char cIllegal : ILLEGAL_CHARACTERS_OTHERS)
if (sFilename.indexOf (cIllegal) != -1)
return false;

return true;
}

Expand All @@ -259,28 +253,28 @@ public static boolean isValidWindowsFilename (@Nullable final String sFilename)
return false;

// Check for reserved directories
if (PATH_CURRENT.equals (sFilename) || PATH_PARENT.equals (sFilename))
if (UNIX_PATH_CURRENT.equals (sFilename) || UNIX_PATH_PARENT.equals (sFilename))
return false;

// check for illegal last characters
if (JCStringHelper.endsWithAny (sFilename, ILLEGAL_SUFFIXES))
if (JCStringHelper.endsWithAny (sFilename, WINDOWS_ILLEGAL_SUFFIXES))
return false;

// Check if file name contains any of the illegal characters
for (final char cIllegal : ILLEGAL_CHARACTERS_WINDOWS)
for (final char cIllegal : WINDOWS_ILLEGAL_CHARACTERS)
if (sFilename.indexOf (cIllegal) != -1)
return false;

// check prefixes directly
for (final String sIllegalPrefix : ILLEGAL_PREFIXES)
for (final String sIllegalPrefix : WINDOWS_ILLEGAL_PREFIXES)
if (sFilename.equalsIgnoreCase (sIllegalPrefix))
return false;

// check if filename is prefixed with it
// Note: we can use the default locale, since all fixed names are pure ANSI
// names
final String sUCFilename = sFilename.toUpperCase (Locale.ROOT);
for (final String sIllegalPrefix : ILLEGAL_PREFIXES)
for (final String sIllegalPrefix : WINDOWS_ILLEGAL_PREFIXES)
if (sUCFilename.startsWith (sIllegalPrefix + "."))
return false;

Expand Down

0 comments on commit 390c40a

Please sign in to comment.