* make sure there's no double spaces left behind after stripping illegal characters

This commit is contained in:
Reinhard Pointner 2014-01-10 19:24:25 +00:00
parent 03db21ff20
commit 0b4730f070
2 changed files with 1 additions and 2 deletions

View File

@ -54,7 +54,6 @@ String.metaClass.getNameWithoutExtension = { getNameWithoutExtension(delegate) }
String.metaClass.getExtension = { getExtension(delegate) }
String.metaClass.hasExtension = { String... ext -> hasExtension(delegate, ext) }
String.metaClass.validateFileName = { validateFileName(delegate) }
String.metaClass.validateFilePath = { validateFilePath(delegate) }
// helper for enforcing filename length limits, e.g. truncate filename but keep extension
String.metaClass.truncateFileName = { int limit = 255 -> def ext = getExtension(delegate); def name = getNameWithoutExtension(delegate); return name.substring(0, Math.min(limit - (ext ? 1+ext.length() : 0), name.length())) + (ext ? '.'+ext : '') }

View File

@ -471,7 +471,7 @@ public final class FileUtilities {
*/
public static String validateFileName(CharSequence filename) {
// strip invalid characters from file name
return ILLEGAL_CHARACTERS.matcher(filename).replaceAll("").trim();
return ILLEGAL_CHARACTERS.matcher(filename).replaceAll("").replaceAll("\\s+", " ").trim();
}
public static boolean isInvalidFileName(CharSequence filename) {