Merge pull request #1123 from lookshe/development
Bugfix for issue #1121
This commit is contained in:
commit
8486f47dd9
|
@ -430,23 +430,31 @@ public class Message extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean bodyContainsDownloadable() {
|
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 {
|
try {
|
||||||
URL url = new URL(this.getBody());
|
URL url = new URL(body);
|
||||||
if (!url.getProtocol().equalsIgnoreCase("http")
|
if (!url.getProtocol().equalsIgnoreCase("http")
|
||||||
&& !url.getProtocol().equalsIgnoreCase("https")) {
|
&& !url.getProtocol().equalsIgnoreCase("https")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (url.getPath() == null) {
|
|
||||||
|
String sUrlPath = url.getPath();
|
||||||
|
if (sUrlPath == null || sUrlPath.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String[] pathParts = url.getPath().split("/");
|
|
||||||
String filename;
|
int iSlashIndex = sUrlPath.lastIndexOf('/') + 1;
|
||||||
if (pathParts.length > 0) {
|
|
||||||
filename = pathParts[pathParts.length - 1].toLowerCase();
|
String sLastUrlPath = sUrlPath.substring(iSlashIndex).toLowerCase();
|
||||||
} else {
|
|
||||||
return false;
|
String[] extensionParts = sLastUrlPath.split("\\.");
|
||||||
}
|
|
||||||
String[] extensionParts = filename.split("\\.");
|
|
||||||
if (extensionParts.length == 2
|
if (extensionParts.length == 2
|
||||||
&& Arrays.asList(Downloadable.VALID_IMAGE_EXTENSIONS).contains(
|
&& Arrays.asList(Downloadable.VALID_IMAGE_EXTENSIONS).contains(
|
||||||
extensionParts[extensionParts.length - 1])) {
|
extensionParts[extensionParts.length - 1])) {
|
||||||
|
|
Loading…
Reference in a new issue