From 7803b376b2b6415380cb0317b15456d043d72078 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 21 Jul 2021 22:58:12 +0800 Subject: Fix app crashes when downloading images from a specific domain. --- .../infinityforreddit/activities/LinkResolverActivity.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java index e4b9387c..e0154df2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -119,8 +119,16 @@ public class LinkResolverActivity extends AppCompatActivity { if (authority != null) { if (authority.equals("reddit-uploaded-media.s3-accelerate.amazonaws.com")) { + String unescapedUrl = uri.toString().replace("%2F", "/"); + int lastSlashIndex = unescapedUrl.lastIndexOf("/"); + if (lastSlashIndex < 0 || lastSlashIndex == unescapedUrl.length() - 1) { + deepLinkError(uri); + return; + } + String id = unescapedUrl.substring(lastSlashIndex + 1); Intent intent = new Intent(this, ViewImageOrGifActivity.class); intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, uri.toString()); + intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, id + ".jpg"); startActivity(intent); } else if (authority.equals("v.redd.it")) { Intent intent = new Intent(this, ViewVideoActivity.class); -- cgit v1.2.3