mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
Merge pull request #170 from chrisgward/2.9
Fixing storage of compiled regex
This commit is contained in:
commit
2b7cba936d
1 changed files with 2 additions and 1 deletions
|
@ -23,11 +23,12 @@ public class Util
|
|||
private final static Logger logger = Logger.getLogger("Minecraft");
|
||||
private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]");
|
||||
private final static Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]");
|
||||
private final static Pattern BADFILENAMES = Pattern.compile("^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\\.(.+))?$", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.COMMENTS);
|
||||
|
||||
public static String sanitizeFileName(final String name)
|
||||
{
|
||||
String newName = INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
|
||||
if(Pattern.compile("^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\\.(.+))?$", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.COMMENTS).matcher(newName).matches())
|
||||
if(BADFILENAMES.matcher(newName).matches())
|
||||
newName = "_" + newName;
|
||||
return newName;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue