mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Fix extension replacement, add related tests
Makes sure findUniqueFilename receives filenames with an extension. More robust extension replacement rules.
This commit is contained in:
parent
1bdcf3fda0
commit
b91c9776f6
5 changed files with 51 additions and 17 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue