filter sequences of more than 3 ltr-rtl

This commit is contained in:
Daniel Gultsch 2018-05-04 10:11:24 +02:00
parent 7b3d871f28
commit 96224c0fc6
3 changed files with 17 additions and 7 deletions

View File

@ -606,7 +606,7 @@ public class Message extends AbstractEntity {
}
public SpannableStringBuilder getMergedBody() {
SpannableStringBuilder body = new SpannableStringBuilder(this.body.trim());
SpannableStringBuilder body = new SpannableStringBuilder(MessageUtils.filterLtrRtl(this.body).trim());
Message current = this;
while (current.mergeable(current.next())) {
current = current.next();
@ -616,7 +616,7 @@ public class Message extends AbstractEntity {
body.append("\n\n");
body.setSpan(new MergeSeparator(), body.length() - 2, body.length(),
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
body.append(current.getBody().trim());
body.append(MessageUtils.filterLtrRtl(current.getBody()).trim());
}
return body;
}

View File

@ -31,11 +31,17 @@ package eu.siacs.conversations.utils;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.http.AesGcmURLStreamHandler;
public class MessageUtils {
private static final Pattern LTR_RTL = Pattern.compile("(\\u200E[^\\u200F]*\\u200F){3,}");
private static final String EMPTY_STRING = "";
public static String prepareQuote(Message message) {
final StringBuilder builder = new StringBuilder();
final String body = message.getMergedBody().toString();
@ -79,4 +85,8 @@ public class MessageUtils {
return false;
}
}
public static String filterLtrRtl(String body) {
return LTR_RTL.matcher(body).replaceFirst(EMPTY_STRING);
}
}

View File

@ -283,7 +283,7 @@ public class UIHelper {
} else if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
return new Pair<>(getFileDescriptionString(context, message), true);
} else {
final String body = message.getBody();
final String body = MessageUtils.filterLtrRtl(message.getBody());
if (body.startsWith(Message.ME_COMMAND)) {
return new Pair<>(body.replaceAll("^" + Message.ME_COMMAND,
UIHelper.getMessageDisplayName(message) + " "), false);