From e391c15341f014949f363bc3fdddc7604ba57060 Mon Sep 17 00:00:00 2001 From: stom79 Date: Wed, 9 May 2018 15:52:26 +0200 Subject: [PATCH] Fixes issue #445: catastrophic backtracking --- .../mastodon/client/Entities/Status.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java index efdeda405..1046135be 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java @@ -35,6 +35,8 @@ import android.text.style.ClickableSpan; import android.text.style.ForegroundColorSpan; import android.text.style.ImageSpan; import android.text.style.URLSpan; +import android.util.Log; +import android.util.Patterns; import android.view.View; import com.bumptech.glide.Glide; @@ -637,11 +639,16 @@ public class Status implements Parcelable{ matcher = Patterns.WEB_URL.matcher(spannableString); else matcher = Helper.urlPattern.matcher(spannableString);*/ - matcher = Helper.urlPattern.matcher(spannableString); + matcher = Patterns.WEB_URL.matcher(spannableString); while (matcher.find()){ int matchStart = matcher.start(1); int matchEnd = matcher.end(); + Log.v(Helper.TAG,"matchStart: " + matchStart); + Log.v(Helper.TAG,"matchEnd: " + matchEnd); + final String url = spannableString.toString().substring(matchStart, matchEnd); + Log.v(Helper.TAG,"url: " + url); + Log.v(Helper.TAG,"spannableString.toString().length(): " + spannableString.toString().length()); if( matchStart >= 0 && matchEnd <= spannableString.toString().length() && matchEnd >= matchStart) spannableString.setSpan(new ClickableSpan() { @Override @@ -659,11 +666,12 @@ public class Status implements Parcelable{ }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); - if( matchStart >= 0 && matchEnd <= spannableString.toString().length() && matchEnd >= matchStart) + Log.v(Helper.TAG,"spannableString.toString().length(): " + spannableString.toString().length()); + /* if( matchStart >= 0 && matchEnd <= spannableString.toString().length() && matchEnd >= matchStart) spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, theme==Helper.THEME_DARK?R.color.mastodonC2:R.color.mastodonC4)), matchStart, matchEnd, - Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + Spanned.SPAN_INCLUSIVE_EXCLUSIVE);*/ } - + Log.v(Helper.TAG,"mentions: " + mentions); //Deals with mention to make them clickable if( mentions != null && mentions.size() > 0 ) { //Looping through accounts which are mentioned @@ -700,6 +708,7 @@ public class Status implements Parcelable{ } } + Log.v(Helper.TAG,"tag: " + spannableString); matcher = Helper.hashtagPattern.matcher(spannableString); while (matcher.find()){ int matchStart = matcher.start(1); @@ -725,6 +734,7 @@ public class Status implements Parcelable{ spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, theme==Helper.THEME_DARK?R.color.mastodonC2:R.color.mastodonC4)), matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } + Log.v(Helper.TAG,"spannableString: " + spannableString); return spannableString; }