diff --git a/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java b/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java index a849a5e775..9bc08332fb 100644 --- a/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java +++ b/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java @@ -147,6 +147,11 @@ public class LinkPreviewRepository implements InjectableType { imageUrl = Optional.absent(); } + if (imageUrl.isPresent() && !LinkPreviewUtil.isVaildMimeType(imageUrl.get())) { + Log.i(TAG, "Image URL was invalid mime type. Skipping."); + imageUrl = Optional.absent(); + } + callback.onComplete(new Metadata(title, imageUrl)); } }); diff --git a/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewUtil.java b/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewUtil.java index abe9018061..be7a586e7a 100644 --- a/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewUtil.java +++ b/src/org/thoughtcrime/securesms/linkpreview/LinkPreviewUtil.java @@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.util.DateUtils; import org.thoughtcrime.securesms.util.Util; import org.whispersystems.libsignal.util.guava.Optional; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -96,6 +97,15 @@ public final class LinkPreviewUtil { } } + public static boolean isVaildMimeType(@NonNull String url) { + String[] vaildMimeType = {"jpg", "png", "gif", "jpeg"}; + if (url.contains(".")) { + String extenstion = url.substring(url.lastIndexOf(".") + 1).toLowerCase(); + return Arrays.asList(vaildMimeType).contains(extenstion); + } + return true; + } + public static @NonNull OpenGraph parseOpenGraphFields(@Nullable String html) { return parseOpenGraphFields(html, text -> Html.fromHtml(text).toString()); }