aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-05 20:44:05 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-05 20:44:05 +0200
commit0446624c51942118e74fbba93d40d83a9856723d (patch)
tree60faffcc7994f3b9bc05644e6129b31f5aa620f1 /src
parentf37b1410e17ac8400c8b87a09b81b8af50c74e9d (diff)
filter sequences of more than 3 ltr-rtl
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java4
-rw-r--r--src/main/java/de/pixart/messenger/utils/MessageUtils.java8
-rw-r--r--src/main/java/de/pixart/messenger/utils/UIHelper.java2
3 files changed, 11 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index 0d6d4c18e..8193cbb4d 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -612,7 +612,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();
@@ -621,7 +621,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;
}
diff --git a/src/main/java/de/pixart/messenger/utils/MessageUtils.java b/src/main/java/de/pixart/messenger/utils/MessageUtils.java
index 8a3cdb707..78be415f7 100644
--- a/src/main/java/de/pixart/messenger/utils/MessageUtils.java
+++ b/src/main/java/de/pixart/messenger/utils/MessageUtils.java
@@ -31,11 +31,15 @@ package de.pixart.messenger.utils;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.regex.Pattern;
import de.pixart.messenger.entities.Message;
import de.pixart.messenger.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 +83,8 @@ public class MessageUtils {
return false;
}
}
+
+ public static String filterLtrRtl(String body) {
+ return LTR_RTL.matcher(body).replaceFirst(EMPTY_STRING);
+ }
} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java
index dc15d41e4..e167e8c84 100644
--- a/src/main/java/de/pixart/messenger/utils/UIHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java
@@ -278,7 +278,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);
} else if (message.isGeoUri()) {