aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-04-13 17:57:33 +0200
committerDaniel Gultsch <daniel@gultsch.de>2015-04-13 17:57:33 +0200
commit8486f47dd9c0b50f6bac0204e50417a2b61cf7d7 (patch)
tree146bde9012e4aa067093d841463fd89e696ef007 /src/main/java/eu
parent4bf09bc10b05844f2d1407b1ff72080cc6acb72b (diff)
parent6da77bdf3b38fab3daa0de8776082038d8d62a78 (diff)
Merge pull request #1123 from lookshe/development
Bugfix for issue #1121
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index 8015eead..21aa7779 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -430,23 +430,31 @@ public class Message extends AbstractEntity {
}
public boolean bodyContainsDownloadable() {
+ /**
+ * there are a few cases where spaces result in an unwanted behavior, e.g.
+ * "http://example.com/image.jpg" text that will not be shown /abc.png"
+ * or more than one image link in one message.
+ */
+ if (body.contains(" ")) {
+ return false;
+ }
try {
- URL url = new URL(this.getBody());
+ URL url = new URL(body);
if (!url.getProtocol().equalsIgnoreCase("http")
&& !url.getProtocol().equalsIgnoreCase("https")) {
return false;
}
- if (url.getPath() == null) {
- return false;
- }
- String[] pathParts = url.getPath().split("/");
- String filename;
- if (pathParts.length > 0) {
- filename = pathParts[pathParts.length - 1].toLowerCase();
- } else {
+
+ String sUrlPath = url.getPath();
+ if (sUrlPath == null || sUrlPath.isEmpty()) {
return false;
}
- String[] extensionParts = filename.split("\\.");
+
+ int iSlashIndex = sUrlPath.lastIndexOf('/') + 1;
+
+ String sLastUrlPath = sUrlPath.substring(iSlashIndex).toLowerCase();
+
+ String[] extensionParts = sLastUrlPath.split("\\.");
if (extensionParts.length == 2
&& Arrays.asList(Downloadable.VALID_IMAGE_EXTENSIONS).contains(
extensionParts[extensionParts.length - 1])) {