Fix non-escaped string passed as a regexp, which was causing crashes.

This commit is contained in:
Simon Morlat 2017-10-08 19:09:43 +02:00
parent 23a1415692
commit 167586c472

View file

@ -101,6 +101,7 @@ import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Pattern;
import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION; import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
import static org.linphone.FragmentsAvailable.CHAT; import static org.linphone.FragmentsAvailable.CHAT;
@ -1782,14 +1783,14 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp); int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp);
String link = text.substring(indexHttp, indexFinHttp); String link = text.substring(indexHttp, indexFinHttp);
String linkWithoutScheme = link.replace("http://", ""); String linkWithoutScheme = link.replace("http://", "");
text = text.replaceFirst(link, "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>"); text = text.replaceFirst(Pattern.quote(link), "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>");
} }
if (text.contains("https://")) { if (text.contains("https://")) {
int indexHttp = text.indexOf("https://"); int indexHttp = text.indexOf("https://");
int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp); int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp);
String link = text.substring(indexHttp, indexFinHttp); String link = text.substring(indexHttp, indexFinHttp);
String linkWithoutScheme = link.replace("https://", ""); String linkWithoutScheme = link.replace("https://", "");
text = text.replaceFirst(link, "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>"); text = text.replaceFirst(Pattern.quote(link), "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>");
} }
return Compatibility.fromHtml(text); return Compatibility.fromHtml(text);