aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-09-04 19:58:53 +0200
committerDaniel Gultsch <daniel@gultsch.de>2015-09-04 19:58:53 +0200
commit7eb228d1a598258fe915c6ca722b7fa1a7c49ddf (patch)
treef835da34a34e56c7a3601356a6de203779a97b43
parent1848b46195a90487a8b1d9f13b99a790ed68ac48 (diff)
Issues with URLs with multiple dots in file. fixes #1373
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 0eff99cf7..bfb26446d 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -506,17 +506,25 @@ public class Message extends AbstractEntity {
private static String extractRelevantExtension(URL url) {
String path = url.getPath();
+ return extractRelevantExtension(path);
+ }
+
+ private static String extractRelevantExtension(String path) {
if (path == null || path.isEmpty()) {
return null;
}
+
String filename = path.substring(path.lastIndexOf('/') + 1).toLowerCase();
- String[] extensionParts = filename.split("\\.");
- if (extensionParts.length == 2) {
- return extensionParts[extensionParts.length - 1];
- } else if (extensionParts.length == 3 && Arrays
- .asList(Transferable.VALID_CRYPTO_EXTENSIONS)
- .contains(extensionParts[extensionParts.length - 1])) {
- return extensionParts[extensionParts.length -2];
+ int dotPosition = filename.lastIndexOf(".");
+
+ if (dotPosition != -1) {
+ String extension = filename.substring(dotPosition + 1);
+ // we want the real file extension, not the crypto one
+ if (Arrays.asList(Transferable.VALID_CRYPTO_EXTENSIONS).contains(extension)) {
+ return extractRelevantExtension(path.substring(0,dotPosition));
+ } else {
+ return extension;
+ }
}
return null;
}