From 1b2602ac3ac95ab556062ca4d9f336675d26459d Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 1 Dec 2020 23:53:37 +0800 Subject: [PATCH] Maybe fix IndexOutOfBoundsException when parsing spoiler syntax. --- .../activities/FullMarkdownActivity.java | 5 +++++ .../adapters/CommentAndPostRecyclerViewAdapter.java | 10 ++++++++++ .../adapters/CommentsListingRecyclerViewAdapter.java | 5 +++++ .../adapters/MessageRecyclerViewAdapter.java | 5 +++++ 4 files changed, 25 insertions(+) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index f874244c..5e0ce147 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -145,6 +145,11 @@ public class FullMarkdownActivity extends BaseActivity { int start = 0; boolean find = false; while (matcher.find(start)) { + if (markdownStringBuilder.length() < 4 + || matcher.start() < 0 + || matcher.end() > markdownStringBuilder.length()) { + break; + } find = true; markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index 682f7157..6a4dc4db 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -279,6 +279,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter markdownStringBuilder.length()) { + break; + } find = true; markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); @@ -375,6 +380,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter markdownStringBuilder.length()) { + break; + } find = true; markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index fad4476f..25f19384 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -136,6 +136,11 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter markdownStringBuilder.length()) { + break; + } find = true; markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java index b4d74f96..04ec62f2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -121,6 +121,11 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter markdownStringBuilder.length()) { + break; + } find = true; markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); markdownStringBuilder.delete(matcher.start(), matcher.start() + 2);