Issues with URLs with multiple dots in file. fixes #1373

This commit is contained in:
Daniel Gultsch 2015-09-04 19:58:53 +02:00
parent 1848b46195
commit 7eb228d1a5

View file

@ -506,17 +506,25 @@ public class Message extends AbstractEntity {
private static String extractRelevantExtension(URL url) { private static String extractRelevantExtension(URL url) {
String path = url.getPath(); String path = url.getPath();
return extractRelevantExtension(path);
}
private static String extractRelevantExtension(String path) {
if (path == null || path.isEmpty()) { if (path == null || path.isEmpty()) {
return null; return null;
} }
String filename = path.substring(path.lastIndexOf('/') + 1).toLowerCase(); String filename = path.substring(path.lastIndexOf('/') + 1).toLowerCase();
String[] extensionParts = filename.split("\\."); int dotPosition = filename.lastIndexOf(".");
if (extensionParts.length == 2) {
return extensionParts[extensionParts.length - 1]; if (dotPosition != -1) {
} else if (extensionParts.length == 3 && Arrays String extension = filename.substring(dotPosition + 1);
.asList(Transferable.VALID_CRYPTO_EXTENSIONS) // we want the real file extension, not the crypto one
.contains(extensionParts[extensionParts.length - 1])) { if (Arrays.asList(Transferable.VALID_CRYPTO_EXTENSIONS).contains(extension)) {
return extensionParts[extensionParts.length -2]; return extractRelevantExtension(path.substring(0,dotPosition));
} else {
return extension;
}
} }
return null; return null;
} }