Bugfix: picture name suffixes were malformed on export and thus could not be re-imported.

This commit is contained in:
Dennis Guse
2019-11-29 22:23:00 +01:00
parent e35cbc343a
commit bf7fc28bb0
2 changed files with 8 additions and 2 deletions
@@ -60,10 +60,15 @@ public class FileUtilsTest extends TestCase {
*/ */
public void testSanitizeFileName() { public void testSanitizeFileName() {
String name = "Swim\10ming-^across:/the/ pacific (ocean)."; String name = "Swim\10ming-^across:/the/ pacific (ocean).";
String expected = "Swim_ming-^across_the_ pacific (ocean)_"; String expected = "Swim_ming-^across_the_ pacific (ocean).";
assertEquals(expected, FileUtils.sanitizeFileName(name)); assertEquals(expected, FileUtils.sanitizeFileName(name));
} }
public void testSanitizeFileNameWithSuffix() {
String name = "FileName.jpeg";
assertEquals(name, FileUtils.sanitizeFileName(name));
}
/** /**
* Tests {@link FileUtils#sanitizeFileName(String)} with i18n characters (in Chinese and Russian). * Tests {@link FileUtils#sanitizeFileName(String)} with i18n characters (in Chinese and Russian).
* Verifies that they are allowed. * Verifies that they are allowed.
@@ -204,12 +204,13 @@ public class FileUtils {
* *
* @param name name * @param name name
*/ */
// TODO Check if this function is still needed.
public static String sanitizeFileName(String name) { public static String sanitizeFileName(String name) {
StringBuilder builder = new StringBuilder(name.length()); StringBuilder builder = new StringBuilder(name.length());
for (int i = 0; i < name.length(); i++) { for (int i = 0; i < name.length(); i++) {
int codePoint = name.codePointAt(i); int codePoint = name.codePointAt(i);
char character = name.charAt(i); char character = name.charAt(i);
if (Character.isLetterOrDigit(character) || codePoint > 127 || isSpecialFat32(character)) { if (Character.isLetterOrDigit(character) || codePoint > 127 || isSpecialFat32(character) || character == '.') {
builder.appendCodePoint(codePoint); builder.appendCodePoint(codePoint);
} else { } else {
builder.append("_"); builder.append("_");