Fixes issue #445: catastrophic backtracking

This commit is contained in:
stom79 2018-05-09 15:52:26 +02:00
parent 4fb85ac19b
commit e391c15341
1 changed files with 14 additions and 4 deletions

View File

@ -35,6 +35,8 @@ import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan; import android.text.style.ImageSpan;
import android.text.style.URLSpan; import android.text.style.URLSpan;
import android.util.Log;
import android.util.Patterns;
import android.view.View; import android.view.View;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
@ -637,11 +639,16 @@ public class Status implements Parcelable{
matcher = Patterns.WEB_URL.matcher(spannableString); matcher = Patterns.WEB_URL.matcher(spannableString);
else else
matcher = Helper.urlPattern.matcher(spannableString);*/ matcher = Helper.urlPattern.matcher(spannableString);*/
matcher = Helper.urlPattern.matcher(spannableString); matcher = Patterns.WEB_URL.matcher(spannableString);
while (matcher.find()){ while (matcher.find()){
int matchStart = matcher.start(1); int matchStart = matcher.start(1);
int matchEnd = matcher.end(); int matchEnd = matcher.end();
Log.v(Helper.TAG,"matchStart: " + matchStart);
Log.v(Helper.TAG,"matchEnd: " + matchEnd);
final String url = spannableString.toString().substring(matchStart, 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) if( matchStart >= 0 && matchEnd <= spannableString.toString().length() && matchEnd >= matchStart)
spannableString.setSpan(new ClickableSpan() { spannableString.setSpan(new ClickableSpan() {
@Override @Override
@ -659,11 +666,12 @@ public class Status implements Parcelable{
}, },
matchStart, matchEnd, matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE); 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, 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 //Deals with mention to make them clickable
if( mentions != null && mentions.size() > 0 ) { if( mentions != null && mentions.size() > 0 ) {
//Looping through accounts which are mentioned //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); matcher = Helper.hashtagPattern.matcher(spannableString);
while (matcher.find()){ while (matcher.find()){
int matchStart = matcher.start(1); 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, 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,"spannableString: " + spannableString);
return spannableString; return spannableString;
} }