Browse Source

fix(StoryViewerFragment): crash when parsing unexpected Instagram id

renovate/org.robolectric-robolectric-4.x
Pablo Rodríguez Caballero 4 years ago
parent
commit
0afe482b86
No known key found for this signature in database GPG Key ID: 2788EF5E4218A68E
  1. 20
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java

20
app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java

@ -65,6 +65,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import awais.instagrabber.BuildConfig; import awais.instagrabber.BuildConfig;
import awais.instagrabber.R; import awais.instagrabber.R;
@ -735,7 +737,7 @@ public class StoryViewerFragment extends Fragment {
return; return;
} }
final HighlightModel model = models.get(currentFeedStoryIndex); final HighlightModel model = models.get(currentFeedStoryIndex);
currentStoryMediaId = model.getId();
currentStoryMediaId = parseStoryMediaId(model.getId());
currentStoryUsername = model.getTitle(); currentStoryUsername = model.getTitle();
fetchOptions = StoryViewerOptions.forUser(Long.parseLong(currentStoryMediaId), currentStoryUsername); fetchOptions = StoryViewerOptions.forUser(Long.parseLong(currentStoryMediaId), currentStoryUsername);
break; break;
@ -1146,4 +1148,20 @@ public class StoryViewerFragment extends Fragment {
resetView(); resetView();
} }
} }
/**
* Parses the Story's media ID. For user stories this is a number, but for archive stories
* this is "archiveDay:" plus a number.
*/
private static String parseStoryMediaId(String rawId) {
final String regex = "(?:archiveDay:)?(.+)";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(rawId);
if (matcher.matches() && matcher.groupCount() >= 1) {
return matcher.group(1);
}
return rawId;
}
} }
Loading…
Cancel
Save