Fix extension replacement, add related tests

Makes sure findUniqueFilename receives filenames with an extension.
More robust extension replacement rules.
This commit is contained in:
Yusuke Matsubara 2016-08-16 07:39:38 +09:00
parent 1bdcf3fda0
commit b91c9776f6
5 changed files with 51 additions and 17 deletions

View file

@ -240,4 +240,18 @@ public class Utils {
return false;
}
}
public static String fixExtension(String title, String extension) {
// People are used to ".jpg" more than ".jpeg" which the system gives us.
if (extension != null && extension.toLowerCase().equals("jpeg")) {
extension = "jpg";
}
if (title.toLowerCase().endsWith(".jpeg")) {
title = title.replaceFirst("\\.jpeg$", ".jpg");
}
if (extension != null && !title.toLowerCase().endsWith("." + extension.toLowerCase())) {
title += "." + extension;
}
return title;
}
}