aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-06-17 00:03:57 +0200
committerChristian Schneppe <christian@pix-art.de>2018-06-17 00:03:57 +0200
commit7dfb1881420dfc1ba0c309bbbf2c30fc2883fb18 (patch)
tree9aea8953a1059026827954ef0a1bc4c369f4078b /src/main/java/de/pixart/messenger/ui
parent5db026412b80e2f33557595748a14b741ececa2f (diff)
Improved URL matching
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui')
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index 0c2238cdb..5d38094bf 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -15,6 +15,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
+import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.ColorInt;
import android.support.v4.app.ActivityCompat;
@@ -116,7 +117,43 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
};
- private static final Linkify.MatchFilter WEBURL_MATCH_FILTER = (cs, start, end) -> start < 1 || (cs.charAt(start - 1) != '@' && cs.charAt(start - 1) != '.' && !cs.subSequence(Math.max(0, start - 3), start).equals("://"));
+ private static String removeTrailingBracket(final String url) {
+ int numOpenBrackets = 0;
+ for (char c : url.toCharArray()) {
+ if (c == '(') {
+ ++numOpenBrackets;
+ } else if (c == ')') {
+ --numOpenBrackets;
+ }
+ }
+ if (numOpenBrackets != 0 && url.charAt(url.length() - 1) == ')') {
+ return url.substring(0, url.length() - 1);
+ } else {
+ return url;
+ }
+ }
+
+ private static final Linkify.MatchFilter WEBURL_MATCH_FILTER = (cs, start, end) -> {
+ if (start > 0) {
+ if (cs.charAt(start - 1) == '@' || cs.charAt(start - 1) == '.'
+ || cs.subSequence(Math.max(0, start - 3), start).equals("://")) {
+ return false;
+ }
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ if (end < cs.length()) {
+ // Reject strings that were probably matched only because they contain a dot followed by
+ // by some known TLD (see also comment for WORD_BOUNDARY in Patterns.java)
+ if (Character.isAlphabetic(cs.charAt(end - 1)) && Character.isAlphabetic(cs.charAt(end))) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ };
+
private static final Linkify.MatchFilter XMPPURI_MATCH_FILTER = (s, start, end) -> {
XmppUri uri = new XmppUri(s.subSequence(start, end).toString());
return uri.isJidValid();
@@ -140,22 +177,6 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
updatePreferences();
}
- private static String removeTrailingBracket(final String url) {
- int numOpenBrackets = 0;
- for (char c : url.toCharArray()) {
- if (c == '(') {
- ++numOpenBrackets;
- } else if (c == ')') {
- --numOpenBrackets;
- }
- }
- if (numOpenBrackets != 0 && url.charAt(url.length() - 1) == ')') {
- return url.substring(0, url.length() - 1);
- } else {
- return url;
- }
- }
-
public static boolean cancelPotentialWork(Message message, ImageView imageView) {
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);